Ever seen this before:
Exception Details: System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
Well 7 hours later after reading and debugging and then reading and debugging some more I finally found a solution. What I was trying to do was something like this
Sub addData(sender As Object, e As EventArgs)
Dim objConn As OleDbConnection
Dim objCmd As OleDbCommand
Dim objRdr As OleDbDataReader
objConn = new OleDbConnection(“xxxx")
objCmd = new OleDbCommand("INSERT INTO MyTable(Name, Email, Password)VALUES (@Name, @Email, @Password);",objConn)
'add all our parameters
objCmd.Parameters.Add("@Name", "UserID")
objCmd.Parameters.Add("@Email", "no@no.com")
objCmd.Parameters.Add("@Password", "hardpassword")
objConn.Open()
Dim blnReturn as Boolean = objCmd.ExecuteNonQuery()
objConn.Close
If blnReturn THen
lblError.Text = "Success"
End If
End Sub
The database being used was Microsoft Access 2003. The insert statement would run perfectly in Access but via ADO.net..nope...Invalid Synatax! As it turns out all the different implementations of SQL have a different set of reserved words, password being one of them. Simply placing [] around the value in question fixes the problem. So what are all these reserved words?
http://office.microsoft.com/en-au/assistance/HP010322491033.aspx - for Access 2003
http://office.microsoft.com/en-au/assistance/HP010322481033.aspx - Access Data Types
http://doc.ddart.net/mssql/sql70/ra-rz_8.htm - SQL Server / MSDE