Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

i have an issue with my sql statement

Posted on 2008-10-18
8
203 Views
Last Modified: 2013-12-25
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)
0
Comment
Question by:Chris Jones
  • 3
  • 3
  • 2
8 Comments
 
LVL 48

Accepted Solution

by:
jpaulino earned 430 total points
ID: 22748598
Hi blingtec903,

Try this way:
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)

Open in new window

0
 
LVL 1

Author Comment

by:Chris Jones
ID: 22748607
oh crap
0
 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 70 total points
ID: 22748611
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

0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22748615
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

0
 
LVL 1

Author Comment

by:Chris Jones
ID: 22748613
thanks i still have other issues but this fixed my problem


thank you
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22748619
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.
0
 
LVL 1

Author Closing Comment

by:Chris Jones
ID: 31507431
great answers it was a not so smart post
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 22748626
>> great answers it was a not so smart post
Small errors/problems make us loose hours :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Error handling in asp.net site 5 34
Problem to line 23 54
Access/Visual Basic Question 3 25
how to loop through and process two columns in excel 8 23
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question