I have an access Database and I am trying to insert records into. This seems like it would be very simple to do and for the most part all the code I have makes sense. I can create queries in VS 15 and they insert into my database, but for some reason my function to insert the records is not working. Can someone see what I am doing wrong here?
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
The function gives me an unhandled exception on the cmd.ExecuteNonQuery
Here is the stack trace
[OleDbException (0x80040e14): Syntax error in INSERT INTO statement.] System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +1130764
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +247
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +208
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +58
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +162
System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +107
WebAppUOP.About.SendData(String eData) in c:\users\debuwa\documents\visual studio 2015\Projects\WebAppUOP\WebAppUOP\AddContact.aspx.vb:41
WebAppUOP.About.SubmitContact() in c:\users\debuwa\documents\visual 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\Projects\WebAppUOP\WebAppUOP\AddContact.aspx.vb:12
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9669962
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String 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
`
Found the issue. I removed the password entry. I am not totally sure why I was not able to use password as a column name, but I removed it and now the app works fine. Thanks everyone for their help
User contributions licensed under CC BY-SA 3.0