如何解决致命的 SQL 语句错误?
我在使用 vb.net 应用程序更新 SQL 数据库中的信息时遇到问题,但最近 我找到了解决方案。但是现在我遇到了另一个问题,如下面的代码所示:
Private Sub cmdupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdupdate.Click
Dim conn As New MySqlConnection
Dim myCommand As New MySqlCommand
'#######
conn.ConnectionString = "server=" & frmLogin.txtserver.Text & ";" _
& "user id=" & frmLogin.txtusername.Text & ";" _
& "password=" & frmLogin.txtpassword.Text & ";" _
& "database=in_out"
'#######
myCommand.Connection = conn
myCommand.CommandText = "UPDATE event SET" _
& "status = ?Status " _
& "WHERE user_id = ?UserID AND message_id = ?MessageID AND creator = ?Creator"
myCommand.Parameters.AddWithValue("?UserID", myUserID)
myCommand.Parameters.AddWithValue("?MessageID", cbomessage.SelectedValue)
myCommand.Parameters.AddWithValue("?Status", cbostatus.SelectedItem)
myCommand.Parameters.AddWithValue("?Creator", myUserID)
myCommand.Connection = conn
Try
myCommand.Connection.Open()
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()
Catch myerror As MySqlException
MsgBox("There was an error updating the database: " & myerror.Message)
End Try
End Sub
异常消息是:
<块引用>命令执行期间遇到致命错误。
我不知道这是否只是一个可以轻松修复的语法错误,或者与我的数据库配置有关。
I was having problems updating information in my SQL database using my vb.net application, but recently I found the solution. However now I have run into another problem which is shown in the code below:
Private Sub cmdupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdupdate.Click
Dim conn As New MySqlConnection
Dim myCommand As New MySqlCommand
'#######
conn.ConnectionString = "server=" & frmLogin.txtserver.Text & ";" _
& "user id=" & frmLogin.txtusername.Text & ";" _
& "password=" & frmLogin.txtpassword.Text & ";" _
& "database=in_out"
'#######
myCommand.Connection = conn
myCommand.CommandText = "UPDATE event SET" _
& "status = ?Status " _
& "WHERE user_id = ?UserID AND message_id = ?MessageID AND creator = ?Creator"
myCommand.Parameters.AddWithValue("?UserID", myUserID)
myCommand.Parameters.AddWithValue("?MessageID", cbomessage.SelectedValue)
myCommand.Parameters.AddWithValue("?Status", cbostatus.SelectedItem)
myCommand.Parameters.AddWithValue("?Creator", myUserID)
myCommand.Connection = conn
Try
myCommand.Connection.Open()
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()
Catch myerror As MySqlException
MsgBox("There was an error updating the database: " & myerror.Message)
End Try
End Sub
The exception message is:
Fatal error encountered during command execution.
I don't know if this is simply a syntax error that can be fixed easily, or something to do with my database configuration.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我正确地解读了您的屏幕截图,那么您的 UPDATE 语句将被放在一起:
这会导致:
所以您实际上只是缺少一些空格!
If I decipher your screen shot correctly, then your UPDATE statement is being put together:
This results in:
so you're really only missing some spaces!
之前添加空格;在下面
conn.ConnectionString = "server=" & frmLogin.txtserver.Text & “;” _
谢谢
Add space before ; on below
conn.ConnectionString = "server=" & frmLogin.txtserver.Text & ";" _
Thanks