Link to home
Start Free TrialLog in
Avatar of Chris Jones
Chris JonesFlag for United States of America

asked on

i have an issue with my sql statement

hllo i have a vb app and i have a issue with my sql insert statement can anyone help



STATEMENt

        Dim cmd As New OleDb.OleDbCommand("INSERT INTO item ('Barcode','Type','Name','Date','Comments') VALUES (" & typebind.Text & "," & barcode.Text & "," & name.Text & "," & date1.Text & "," & comments.Text & ")", con)
ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Chris Jones

ASKER

oh crap
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What database platform are you going to?  It appears to be SQL Server, but just to make sure.

Either way, it appears the platform you are using is like SQL Server in that it uses single quotes (') for string literals; therefore, in your values portion of the insert you must wrap your data coming from VB variables with single quotes like this:
(column names should not have wrapped unless this is MySQL and you meant ` instead of '.  You can use [] or "" for columns in SQL Server)
Dim cmd As New OleDb.OleDbCommand("INSERT INTO item ([Type],[Barcode],[Name],[Date],[Comments]) VALUES ('" & typebind.Text & "','" & barcode.Text & "','" & name.Text & "','" & date1.Text & "','" & comments.Text & "')", con)

Open in new window

thanks i still have other issues but this fixed my problem


thank you
I posted too slow and twice somehow.  Anyway, you had Barcode listed first and are putting type in first in values -- Note that was changed above in mine as well.
great answers it was a not so smart post
>> great answers it was a not so smart post
Small errors/problems make us loose hours :)