Solved

i have an issue with my sql statement

Posted on 2008-10-18
8
194 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

777 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