INSERT INTO problem

D

Dazz

Hello

I have made a small app to query a database which works fine. I am now
adding a logging function which writes back to the database in a separate
table. When I update the OleDataAdapter, I get an error saying "Syntax
error in INSERT INTO statement" but the insert statement was automatically
generated by OleDBCommandBuilder.

Can someone help me in finding the problem????

Thanks
Dazz


--------------------------------------------------------------

Dim SQLString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=Booking.mdb"
Dim daLogFile1 As New OleDbDataAdapter()
Dim dtLogFile1 As New DataTable()
Dim dc1 As New OleDb.OleDbConnection(SQLString)
Dim myRow1 As DataRow = dtLogFile1.NewRow

Dim cb1 As New OleDbCommandBuilder(daLogFile1)
'// The SQL statement generated is:
'// INSERT INTO SearchLog( LogNo , Date , Time , PostCode , Product ,
Status ) VALUES ( ? , ? , ? , ? , ? , ? )

'// Create the connection and fill datatable
daLogFile1.SelectCommand = New OleDb.OleDbCommand("SELECT * FROM SearchLog")
daLogFile1.SelectCommand.Connection = dc1
daLogFile1.Fill(dtLogFile1)

'// Create the data to be inserted
myRow1.Item("LogNo") = "000001"
myRow1.Item("Date") = Format(Now, "dd-MM-yyyy")
myRow1.Item("Time") = Format(Now, "HH:mm:ss")
myRow1.Item("PostCode") = txtSearchPC.Text
myRow1.Item("Product") = ""
myRow1.Item("Status") = "Query"

'// Add the completed row to the DataTable
dtLogFile1.Rows.Add(myRow1)

'// "Syntax error in INSERT INTO Statement" on this line
daLogFile1.Update(dtLogFile1)

dtLogFile1.AcceptChanges()
-------------------------------------------------------
 
A

Armin Zingler

Dazz said:
myRow1.Item("Date") = Format(Now, "dd-MM-yyyy")
myRow1.Item("Time") = Format(Now, "HH:mm:ss")

I don't know if it'll solve the problem, but why do you use Text fields for
storing dates and times?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top