0

我使用 vb.net 和 mysqladmin 作为我的数据库。

我的代码有问题,我不知道如何调试它。请帮我..

我的问题是当我单击更新按钮时,错误显示
“CommandText 属性未正确初始化”。

这是代码:

 Dim intDB_ID_Selected As Integer


'Private Sub cmdupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdupdate.Click



If MessageBox.Show("Do you want to update this record?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = vbYes Then

 Dim sqlcommand As New MySqlCommand("UPDATE user_info " & _
                                 " SET name = '" & txtname.Text.Trim & "'," & _
                                 " address = '" & txtaddress.Text.Trim & "', " & _
                                 " age = '" & txtage.Text.Trim & "', " & _
                                 " WHERE id= '" & intDB_ID_Selected & "'", sConnection)
        Call execCmd(SQL)
        load1()
        MsgBox("Record updated successfully.", MsgBoxStyle.Information)
    End If
End Sub `


 Public Sub execCmd(ByVal PstrSQL As String)
    With cmd
        .CommandText = PstrSQL
        .ExecuteNonQuery()
    End With
End Sub

错误行在

.ExecuteNonQuery()

我是这门语言的初学者,所以请帮助我。我求求你们了!!

4

2 回答 2

0

尝试在消息框选择之后执行此操作。cmd 未在 execCmd 中正确初始化。

Dim sqlStr as String = "UPDATE user_info " & _
                       " SET name = '" & txtname.Text.Trim & "'," & _
                       " address = '" & txtaddress.Text.Trim & "', " & _
                       " age = '" & txtage.Text.Trim & "', " & _
                       " WHERE id= '" & intDB_ID_Selected & "'", sConnection)

Dim sqlcommand As New MySqlCommand(sqlStr)
sqlcommand.ExecuteNonQuery()

load1()
MsgBox("Record updated successfully.", MsgBoxStyle.Information)
于 2014-02-19T03:03:59.460 回答
0

什么是 cmd,它是否已初始化?

哦,尝试使用参数化查询。越早养成这个习惯越好。

于 2014-02-19T02:30:17.940 回答