Solved

i have an issue with my sql statement

Posted on 2008-10-18
8
217 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
[X]
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
  • 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 60

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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 60

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 60

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month3 days, 11 hours left to enroll

630 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