I am using Visual Basic 2010 express to control a Ms.Access 2007 database. I am struggling in adding a record to the database.
我使用Visual Basic 2010 express来控制Ms.Access 2007数据库。我正在努力为数据库添加一条记录。
I get the Syntax error in string in query expression 'ID = 4
我在查询表达式'ID = 4中的字符串中得到语法错误
Here is my code :
这是我的代码:
If ComboBox1.Text = "" Or TxtJam.Text = "" Or TxtAudio.Text = "" Then
MessageBox.Show("Data belum lengkap", "Error", MessageBoxButtons.OK, messageBoxIcon.Error)
Else
myqry = "UPDATE TblJadwal SET "
myqry = myqry + " Hari = '" & ComboBox1.Text & "',"
myqry = myqry + " Jam = '" & TxtJam.Text & "',"
myqry = myqry + " Audio = '" & TxtAudio.Text & "'"
myqry = myqry + "WHERE "
myqry = myqry + "ID = " & TxtID.Text & "'"
mycmd = New OleDbCommand(myqry, conn)
mycmd.ExecuteNonQuery()
Call Set1()
End If
and my database
和我的数据库
ID , autonumber
Hari, text
Jadwal, text
Jam, Text
1 个解决方案
#1
4
Here is the problem:
这是问题所在:
"ID = " & TxtID.Text & "'"
You are adding a '
at the end. Incorrect syntax.
你最后加了一个'。语法不正确。
You should either have one at the start as well, or non at all (if ID is numeric).
你应该在开始时有一个,或者根本不有(如果ID是数字)。
"ID = '" & TxtID.Text & "'"
Or:
"ID = " & TxtID.Text
#1
4
Here is the problem:
这是问题所在:
"ID = " & TxtID.Text & "'"
You are adding a '
at the end. Incorrect syntax.
你最后加了一个'。语法不正确。
You should either have one at the start as well, or non at all (if ID is numeric).
你应该在开始时有一个,或者根本不有(如果ID是数字)。
"ID = '" & TxtID.Text & "'"
Or:
"ID = " & TxtID.Text