I am trying to insert into a access db and the PK is an autonumber that is generated by the DB. I am getting a syntax error for the insert statement and dont know why. If possible I would like to return the autonumber value in the same statement.
Here is what I got so far.
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim str As String
Try
cn = New OleDbConnection("Provider=microsoft.Jet.OLEDB.4.0;Data Source=G:\Sean\BMSBonder3_0.mdb;")
cn.Open()
str = String.Format("Insert into Bonder(BonderName, BonderConfig, Date, User) values ('{0}', '{1}', '{2}', '{3}')", addBonder.BonderName _
, xmlString, Date.Now.ToString, Environment.UserName)
MsgBox(str)
cmd = New OleDbCommand(str, cn)
cmd.ExecuteNonQuery()
cn.Close()
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
Return Nothing
Coding in VB.Net obviously. In the query all the field values are set except the autonumber field.