access SQL INSERT error

tigz

Member
Joined
May 21, 2003
Messages
21
hi,

can anyone help with this please.

im trying to execute an INSERT INTO SQL command in my vb.net code, but i keep getting the error message "syntax error in INSERT INTO command". Im running my app on windows server2000 at the moment, but i dont think that would cause a problem. Ive tried executing the command on an access97 and 2000 version of my database. ive tried making my table names in the database as simple as possible and even reduced the number of columns in my database to just one for testing purposes and i still get the error message. im certain theres nothing wrong with the syntax - any ideas?

heres my code.

Dim sConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";Data Source=" & Application.StartupPath & "\Data\db.mdb;Mode=Share Deny None;Persist Security Info=True"
objConn = New System.Data.OleDb.OleDbConnection(sConnection)

Dim sSQL As String

sSQL = "insert into user (IDNO) values (657)"


Dim objCmd As New System.Data.OleDb.OleDbCommand(sSQL, objConn)
Try
opens and executes the prepared query
objConn.Open()
objCmd.ExecuteNonQuery()
objConn.Close()
Catch ex As System.Exception
MsgBox(ex.Message)
Finally
If objConn.State = ConnectionState.Open Then
objConn.Close()
End If
End Try


the code crashes in the try statement when it executes the objcmd.executeNonQuery() statement. I know that its definitely opening the connection properly, as far as i can tell ive narrowed it down to the contents of the sSQL string variable being the problem. if its not this then it must be an external thing that i havent set up correctly on the windows or dtabase system. do i need to do something in the ODBC links screen, in the Administrative tools icon in the control panel? all ive done externally to vb.net is install ms access 2000 and created a simple database for testing this command out before doing the rest of my code.

ive tried searching for help on other threads on here, but theyre syntax looks the same as mine so im clueless.

many thanks for any help
 
its alright thanks, ive solved it. user (the name of one of my tables) is a reserved word in access so it messes up.
 
Back
Top