我的代码不起作用。我做得对吗?

时间:2016-06-23 07:27:04

标签: mysql .net vb.net

我想要实现的目标是:

我会选择要更新的列,这就是为什么我正在尝试我的代码但没有工作,现在我觉得我需要一些帮助。

Dim btnup="col1"
Dim btnval="1"
Try
    Dim mysqlconn As New MySqlConnection
    Dim conStr As String
    conStr = "Server=localhost; user id=root; password=; database=dnc_floor"
    mysqlconn = New MySqlConnection(conStr)
    mysqlconn.Open()
    Dim update As String
    Dim cmd As MySqlCommand
    update = "Update floor set ='" & btnup & "'=btnval  where ID='" & Day & "'"
    cmd = New MySqlCommand(update, mysqlconn)
    cmd.ExecuteNonQuery()
    Dim check As String = cmd.ExecuteNonQuery()
    MsgBox("Saved")
    mysqlconn.Close()
Catch ex As MySqlException
    MessageBox.Show("Check your connection with your database")
Finally
    mysqlconn.Dispose()
End Try

1 个答案:

答案 0 :(得分:1)

更新字符串可能有误。也许你想到了:

  update = "Update floor set " & btnup & " ='" & btnval & "'  where ID= '" & Day & "'"