Help this is not new and I know the problem but cant fix it. I am rewriting a program in vb.net and the original Access database has a field name call 'Day' (Reserved Word)
I want to keep the name as I cannot change the data structure not practical(too many copies about)
I am using dataset and databinded controls. The following is snippets from the source code.
VB Code:
Dim stSQL As String = "Select ID,[Day],PilotID Where PilotID=" & PilotID da = New OleDbDataAdapter(stSQL, pConnection) ds.Clear() Try da.Fill(ds, "tblLogbook") Catch ex As Exception End Try
My controls are binded as such:
VB Code:
txtPilotID.DataBindings.Add("Value", dbLogbook.ds, "tblLogbook.PilotID") txtDay.DataBindings.Add("Value", dbLogbook.ds, "tblLogbook.Day")
my insertcommand is as follows
VB Code:
cmdInsert.Connection = FTLDb ' FTLDb is a declared connection object cmdInsert.CommandText = "Insert Into tblLogbook (PIlotID,[Day]) Values (@PIlotID,@Day)" cmdInsert.Parameters.Add(New OleDbParameter("@PIlotID", "PIlotID")) cmdInsert.Parameters.Add(New OleDbParameter("@Day", "[Day]")) da.InsertCommand = cmdInsert
When I call
VB Code:
da.Update(ds, "tblLogbook")
I get the error message 'Syntax Error in INSERT INTO statement'
I know the problem is Day because if I change the name in the database to something else, it works. I am looking for a resolution without changing the datastructure. I know I have to use square brackets but where?




Reply With Quote