急问:“INSERT INTO 语句的语法错误。”请求帮忙分析原因
Dim msgTo As Integer = CInt(Request.Cookies("QQ").Value)
Dim msgFrom As Integer = CInt(Request.QueryString("QQ"))
Dim strSQL As String = "Insert into Msg(to,from,MsgContent) Values(" & msgTo & "," & msgFrom & ",'" & tbMsg.Text & "')"
Dim Comm As OleDbCommand = New OleDbCommand(strSQL, Conn)
Try
Comm.ExecuteNonQuery()
lblState.Text = "发送成功!"
Catch ex As Exception
lblState.Text = "发送失败!"
TextBox1.Text = strSQL & " " & ex.ToString
End Try
其中表Msg里的to,from都为“数字”类型,MsgContent为“文本”类型,使用的是Access数据库。
然后我把SQL语句用一个Label显示出来,如下:
Insert into Msg(to,from,MsgContent) Values(6666,12345,'你好!')
出现如下错误提示:
System.Data.OleDb.OleDbException: INSERT INTO 语句的语法错误。
在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
在 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
在 System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
在 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
在 System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
在 Msg.btnSend_Click(Object sender, EventArgs e)
请问是什么原因,应该没有错啊!
------解决方案--------------------如果是关键字就用[from] 代替~~
------解决方案--------------------"Insert into Msg([to],[from],MsgContent) Values('" & msgTo & "','" & msgFrom & "', '" & tbMsg.Text & " ')"