我有一个访问数据库,我正在尝试插入记录。这看起来很简单,并且在大多数情况下我所有的代码都是有意义的。我可以在VS 15中创建查询并将它们插入到我的数据库中,但由于某种原因,我插入记录的功能无效。有人能看到我在这里做错了吗?
Private Function SendData(eData As String)
Dim connectString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=|DataDirectory|web407db.mdb"
Dim cn As OleDbConnection = New OleDbConnection(connectString)
cn.Open()
Dim selectString As String = "INSERT INTO users(encryptID, firstName, lastName, userName, password, email) VALUES ('" & GetHash(eData) & "', '" & fName_in.Text & "', '" & lName_in.Text & "', '" & uName_in.Text & "', '" & pWord_in.Text & "', '" & email_in.Text & "')"
Dim cmd As OleDbCommand = New OleDbCommand(selectString, cn)
cmd.ExecuteNonQuery()
cn.Close()
Return True
End Function
该函数在cmd.ExecuteNonQuery
上给出了一个未处理的异常这是堆栈跟踪
[OleDbException(0x80040e14):INSERT INTO语句中的语法错误。] System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)+1130764
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams,Object& executeResult)+247
System.Data.OleDb.OleDbCommand.ExecuteCommandText(对象&安培; executeResult)+208
System.Data.OleDb.OleDbCommand.ExecuteCommand(的CommandBehavior 行为,对象& executeResult)+58
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(的CommandBehavior 行为,字符串方法)+162
System.Data.OleDb.OleDbCommand.ExecuteNonQuery()+ 107 WebAppUOP.About.SendData(String eData)in c:\ users \ debuwa \ documents \ visual studio 2015 \项目\ WebAppUOP \ WebAppUOP \ AddContact.aspx.vb:41
c:\ users \ debuwa \ documents \ visual中的WebAppUOP.About.SubmitContact() studio 2015 \ Projects \ WebAppUOP \ WebAppUOP \ AddContact.aspx.vb:26
WebAppUOP.About.Button1_Click(Object sender,EventArgs e)in c:\ users \ debuwa \ documents \ visual studio 2015 \项目\ WebAppUOP \ WebAppUOP \ AddContact.aspx.vb:12
System.Web.UI.WebControls.Button.OnClick(EventArgs e)+9669962
System.Web.UI.WebControls.Button.RaisePostBackEvent(字符串 eventArgument)+108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串 eventArgument)+12
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,String eventArgument)+15
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint) 3562
`
答案 0 :(得分:0)
发现了这个问题。我删除了密码条目。我不完全确定为什么我不能使用密码作为列名,但我删除它,现在应用程序工作正常。感谢大家的帮助