更新语句不工作gridview / textboxes [英] Update Statement not working gridview/textboxes

查看:58
本文介绍了更新语句不工作gridview / textboxes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好程序员,我有一个带有三个文本框的窗体,即

Id,名字,年龄。我还在表单中添加了一个gridview,并将其绑定到数据库。

我还添加了三个按钮,用于插入,删除和更新记录。插入是通过文本框完成的,点击按钮后我就可以看到我在gridview中添加了什么。我也可以点击一下按钮删除。



更新的代码不起作用,没有错误信息;

< br $>


Hi programmers out there, I have a windows form with three textboxes namely
Id, name,age . I also added a gridview to the form and its bound to the database.
I also added three buttons one for insert, delete and update records. Insert is done through the textboxes, upon a click of button am able to see what I have added in gridview. Am also able to delete upon a click of a button.

The code for update which is not working, no error message;


Imports System.Data
Imports System.Data.OleDb
Imports System.IO
Imports System.Drawing.Imaging
Imports System.Drawing
Imports System.Collections.Generic
Imports System.ComponentModel

Public Class sss
    Inherits System.Windows.Forms.Form
    Dim con As OleDbConnection = Nothing
    Dim ds As DataSet
    Dim cmd As OleDbCommand = Nothing
    Dim dt As New DataTable
    Dim cs As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\DB.accdb;Persist Security Info=False;"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ID, FName, Age As String
ID = Txtid.Text
FName = txtfullname.Text
Age = txtAge.Text
Dim con As New OleDbConnection(cs)
        Dim cmd As New OleDbCommand()
        cmd.CommandType = CommandType.Text
        cmd.CommandText = "Update ssss SET FName=@FName,Age=@Age WHERE ID=@ID"
        cmd.Connection = con
        con.Open()
        cmd.Parameters.AddWithValue("@ID", ID)
        cmd.Parameters.AddWithValue("@FName", FName)
        cmd.Parameters.AddWithValue("@Age", Age)
cmd.ExecuteNonQuery()
        MessageBox.Show("updated......")

        con.Close()
        Binder()
        	
End Sub
Private Sub Binder()
        Dim con As New OleDbConnection(cs)
        Dim cmd As New OleDbCommand()
        cmd.Connection = con
        con.Open()
        Dim da As New OleDbDataAdapter("select * from ssss", con)
        Dim dt As New DataTable()
        da.Fill(dt)
        DataGridView1.DataSource = dt
        con.Close()
    End Sub

推荐答案

你的sql语句中的参数是@FName,而它是@名称当您使用值添加参数时。
Your parameter is "@FName" in your sql statement while it says "@Name" when you add the parameter with value.


这篇关于更新语句不工作gridview / textboxes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆