Getting a syntax error on my INSERT statment

wjburke2

Active member
Joined
Feb 3, 2009
Messages
29
Programming Experience
Beginner
Can some one look at this please.

I have created a console application that reads a file and updates a Access database. The Open works but i keep getting "Syntax error in INSERT INTO statment" when I try to insert a record. When I list the INSERT statment I get this

INSERT INTO InventoryUpdLog ( PkgId, CompName, UpdDate, Count )
VALUES ('AMB','E1415 R2011',#4/26/2012#,190)

looks ok to me and if I paste it into a query in Access it works fine.
I have been looking at this for two days please help.


Private Sub Add_record(ByVal PkgId As String, ByVal CompName As String, ByVal count As Integer)

Dim intICount As Integer
Dim cmd As OleDbCommand
Dim conn1 As OleDbConnection

conn1 = New OleDbConnection("Provider=" & strProvider & "Data Source=" & strSource)
conn1.Open()

strSQL = "INSERT INTO InventoryUpdLog " & _
"( PkgId, CompName, UpdDate, Count ) " & _
"VALUES ('" & PkgId & "','" & CompName & "',#" & strRunDate & "#," & count & ")"

cmd = New OleDbCommand(strSQL, conn1)

Try
intICount = cmd.ExecuteNonQuery()

Catch e As Exception
Console.WriteLine(e.Message)
End Try

Console.WriteLine("Record Added")

End Sub
 
As it turns out I used Count as a field name on my Table. Count being a reserved word the Insert failed. But thanks for the advice
 
Back
Top