我有更新问题:语法错误 [英] i have problem in update:syntax error
问题描述
这是我的代码:
Dim sqlQRY As String =UPDATE Students SET Company ='&companyTextBox.Text&',last name ='&LastNameTextBox.Text&', first name ='&FirstNameTextBox.Text&',email address ='&emailaddressTextBox.Text&'WHERE student id ='&StudentIDTextBox.Text&'
试试
conn.Open()
Dim cmd As OleDbCommand = New OleDbCommand(sqlQRY,conn)
cmd.ExecuteNonQuery()
MsgBox(记录成功保存...,MsgBoxStyle.Information)
Catch ex As OleDbException
MsgBox(错误:&ex.ToString&vbCrLf)
最后
conn.Close()
结束尝试
this is my code:
Dim sqlQRY As String = "UPDATE Students SET Company='" & companyTextBox.Text & "', last name='" & LastNameTextBox.Text & "', first name='" & FirstNameTextBox.Text & "', email address='" & emailaddressTextBox.Text & "' WHERE student id='" & StudentIDTextBox.Text & "'"
Try
conn.Open()
Dim cmd As OleDbCommand = New OleDbCommand(sqlQRY, conn)
cmd.ExecuteNonQuery()
MsgBox("Record successfully saved...", MsgBoxStyle.Information)
Catch ex As OleDbException
MsgBox("Error: " & ex.ToString & vbCrLf)
Finally
conn.Close()
End Try
推荐答案
从您的字段名称中包含空格,您需要将它们放在括号中。 []
Since your field names have spaces in them you need to put them in brackets. []
UPDATE Students SET [last name] = ...
然而,执行此代码存在巨大的安全问题办法。您需要将值作为参数化查询添加。我建议你阅读Sql注射。
However, there is a huge security problem with doing code this way. You need to add the value in as a parameterized query instead. I would suggest you read up on Sql Injections.
这篇关于我有更新问题:语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!