Click here to Skip to main content
15,892,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

i am using vb.net on framework4 - i have a form with datagrid(readonly) reading data from a Access(MDB). The form also has 9 textboxes. I want to beable to entered text into the textbox and then refresh the datagrid to display the added data...i dont understand what the issue is i keep getting a error - "Syntax error in INSERT INTO statement." can anyone see anything thats not correct, all my fields are correct from my database.

VB
Dim con As New OleDb.OleDbConnection
      Dim cmd As New OleDb.OleDbCommand
      Dim eep As New String("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\odis\carlog.mdb")
      con.ConnectionString = eep

      con.Open()


      'Add To Table
      cmd.Connection = con
      cmd.CommandText = "INSERT INTO CARLOG(ID, CARID, TIME, DATE, MAKE, MODEL, REG, COMPANY, OWNER)" & _
                        " VALUES (" & Me.TextBox1.Text & ",'" & Me.TextBox2.Text & "','" & Me.TextBox3.Text & "','" & Me.TextBox4.Text & "','" & Me.TextBox5.Text & "','" & Me.TextBox6.Text & "','" & Me.TextBox7.Text & "','" & Me.TextBox8.Text & "','" & Me.TextBox9.Text & "')"

      cmd.ExecuteNonQuery()

      con.Close()


Any help or pointers would be muchh appreciated! :)

Thanks In Advance

- Steve
Posted

1 solution

use parametrized queries for avoiding SQL injection. Example:

http://msdn.microsoft.com/en-us/library/bb738521.aspx[^]

Also, do not use reserved words as column/table names.
List of reserved words in MS Access:

http://support.microsoft.com/kb/286335[^]

If you still want to use the query you are using then enclose the column name in brackets which are reserved words. example:

cmd.CommandText = "INSERT INTO CARLOG (ID, CARID, [TIME], [DATE], MAKE, MODEL, REG, COMPANY, OWNER)" & _
 
Share this answer
 
Comments
SIFNOk 29-Nov-11 22:29pm    
Thanks OmPrakash....that was driving mee insane! access did warning me about the reserved words but i think i jumped the gun abit! eeeek! but thank you for this references it will help for further projects :) 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900