471,092 Members | 2,218 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,092 software developers and data experts.

Incorrect Syntax in INSERT INTO STATEMENT

3
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.
Expand|Select|Wrap|Line Numbers
  1.  For i = 0 To dg.Rows.Count - 1
  2.             Main.Command.CommandText = "INSERT INTO Diary (Date1, Time, Appointment) VALUES (?, ?, ?)"
  3.             Dim param1 As System.Data.OleDb.OleDbParameter = New System.Data.OleDb.OleDbParameter("Date1", dg(1, i).Value)
  4.             Dim param2 As System.Data.OleDb.OleDbParameter = New System.Data.OleDb.OleDbParameter("Time", dg(2, i).Value)
  5.             Dim param3 As System.Data.OleDb.OleDbParameter = New System.Data.OleDb.OleDbParameter("Appointment", dg(3, i).Value)
  6.  
  7.             Main.Command.Parameters.Add(param1)
  8.             Main.Command.Parameters.Add(param2)
  9.             Main.Command.Parameters.Add(param3)
  10.  
  11.             Try
  12.                 Main.Command.ExecuteNonQuery()
  13.             Catch ex As Exception
  14.                 MsgBox(ex.Message)
  15.             End Try
  16.             Main.Command.Parameters.Clear()
  17.  
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.
Sep 26 '09 #1
1 2586
Plater
7,872 Expert 4TB
Access uses slightly different forms of SQL, have you verified that your SQL code will work in access before trying to use it in .NET?

Is this "(?, ?, ?)" a valid way to add parameters?
Sep 28 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

14 posts views Thread by bolidev | last post: by
5 posts views Thread by amitbadgi | last post: by
1 post views Thread by Sandesh | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.