Hi, I have a ploblem with an insert statement using an access database, I have the same code with a sql database which works but it doesn't seem to work on access. Could someone please help.
[code=VBNET]
For i = 0 To dg.Rows.Count - 1
Main.Command.Co mmandText = "INSERT INTO Diary (Date1, Time, Appointment) VALUES (?, ?, ?)"
Dim param1 As System.Data.Ole Db.OleDbParamet er = New System.Data.Ole Db.OleDbParamet er("Date1", dg(1, i).Value)
Dim param2 As System.Data.Ole Db.OleDbParamet er = New System.Data.Ole Db.OleDbParamet er("Time", dg(2, i).Value)
Dim param3 As System.Data.Ole Db.OleDbParamet er = New System.Data.Ole Db.OleDbParamet er("Appointment ", dg(3, i).Value)
Main.Command.Pa rameters.Add(pa ram1)
Main.Command.Pa rameters.Add(pa ram2)
Main.Command.Pa rameters.Add(pa ram3)
Try
Main.Command.Ex ecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Messa ge)
End Try
Main.Command.Pa rameters.Clear( )
[/code]
i get "syntax error in INSERT INTO Statement" i've tried writing the values directly into the command text and that gives me the same error. Am I missing something totally obvious here?
Thanks in advance.
[code=VBNET]
For i = 0 To dg.Rows.Count - 1
Main.Command.Co mmandText = "INSERT INTO Diary (Date1, Time, Appointment) VALUES (?, ?, ?)"
Dim param1 As System.Data.Ole Db.OleDbParamet er = New System.Data.Ole Db.OleDbParamet er("Date1", dg(1, i).Value)
Dim param2 As System.Data.Ole Db.OleDbParamet er = New System.Data.Ole Db.OleDbParamet er("Time", dg(2, i).Value)
Dim param3 As System.Data.Ole Db.OleDbParamet er = New System.Data.Ole Db.OleDbParamet er("Appointment ", dg(3, i).Value)
Main.Command.Pa rameters.Add(pa ram1)
Main.Command.Pa rameters.Add(pa ram2)
Main.Command.Pa rameters.Add(pa ram3)
Try
Main.Command.Ex ecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Messa ge)
End Try
Main.Command.Pa rameters.Clear( )
[/code]
i get "syntax error in INSERT INTO Statement" i've tried writing the values directly into the command text and that gives me the same error. Am I missing something totally obvious here?
Thanks in advance.
Comment