jacob Denis jacob Denis - 5 months ago 6
SQL Question

My code is not working. Am I doing it right?

what i wanted to achieve is, i will choose what column should i update, this is why i am experimenting on my code but did not work and now i think i need some help.

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

Answer

The update string is probably wrong. Maybe u think of that:

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