I am trying to insert into a DB with has the following columns: ID (autonumber), BonderIdentifier (text), Username (text), Login (date), Logout (date).
BonderIdentifier, Username, Login is the PK.
Here is what I do:
Public Function submitNewToDB(ByVal sessionData As BonderSession) As Boolean
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 Session ([BonderIdentifier], [Username], [Login]) values ('{0}', '{1}', '{2}')", sessionData.bonderIdentifier _
, sessionData.username, sessionData.login)
cmd = New OleDbCommand(str, cn)
cmd.ExecuteNonQuery()
cn.Close()
Catch ex As Exception
Return False
End Try
Return True
End Function
Like I said I get an insert into error and I dont know why. Nothing is in the DB yet and the table is created.
EDIT I ran the built string in Access as such:
Insert into Session ([BonderIdentifier], [Username], [Login]) values ('Mork', 'sean', '2/23/2010 11:12:42 AM')
And it works.... but in VS it doesnt.