Solved

i have an issue with my sql statement

Posted on 2008-10-18
8
176 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now