Syntax Error in INSERT INTO statement

JohnM

Well-known member
Joined
Jul 2, 2004
Messages
116
Location
Massachusetts
Programming Experience
1-3
I need to insert 39 values into an access database from a .net application. When I run my program I get an Systax error in the INSERT INTO statement. I have compare the access field names with the names I typed in the INSERT Statement and see no errors, I have checked the variable's (in the program) formats (integer, single, ect) with the formats in the database and they match.

The error trapping I have used is below. It doesn't tell me very specific information on where the error is. Is there something else I can add to the error trapping that would give me more specific information on where the error is? Thank you for your time. My eyes are going bugging trying to see a mistake.

One thing I am not very sure about though is the way to concatenate the lines because of the length of typing 39 variables. Part of it is shown here

& n1 & "','" & s0 & "',' " & o11 & "'" & _

John M


Try
Dim MyDataReader As OleDbDataReader = Objcommand.ExecuteReader
While MyDataReader.Read
MsgBox(MyDataReader.GetName(4).ToString)
MsgBox(MyDataReader.GetValue(4).ToString)
End While
MyDataReader.Close()
cnn1.Close()
Catch exc As System.Exception
MsgBox(" Reader " & exc.ToString)
End Try
 
Thank you

After reading more pages from several books, I added the command string to the messagebox on the TRY and Catch section. When I ran it again, the insert string printed and I saw that I had an extra ' (quote) in 2 different places on 2 variables out of the 39 I had needed to insert. The extra ' (quotes) happened at the point where I concatenated the lines in my command string. I deleted the extra quotes and ran it again, and it worked.

I haven't been able to find a book on SQL that covers how tricky it is to write correctly the quotes and concatenation in the strings.
:eek:
Thank you for responding to my problem.

JohnM
 
Don't concatenate.... use a parameterized query.... then you don't need to worry about the quote marks...

THis link has something on parameter queries.....

or better yet, if this is SQL Server or ORacle, then Stored Procs would be even better.

-tg
 
Thanks

I'll read up on the stored procedures and the parameterized query concepts. Anything to avoid the quotation marks of all sorts.
Thank you.
 
Back
Top