Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 132,116 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,010 people online right now. Registration is fast and FREE... Join Now!




Access Insert Syntax Error....doh!

 
Reply to this topicStart new topic

Access Insert Syntax Error....doh!

StrategicBlob
post 10 Oct, 2008 - 08:15 AM
Post #1


New D.I.C Head

*
Joined: 26 Jun, 2008
Posts: 12


My Contributions


So here is what I got going on. I have recently revamped some code I had wrote previously for my company's computer inventory system. I have gotten adventurous and used Access 2007 because it seems to play nicer than 2003. Anyway, I have run into this issue with the Insert command saying that something about my syntax is not correct. Here is a snippet of what the code looks like.

CODE
Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\mike.mcgillivry\My Documents\mine1.accdb")
        conn.Open()
        '####################################################################  
        Dim addUser As String = "INSERT INTO Computer (ComputerS/N, Brand, User) VALUES (" + txtName2.Text + "','" + txtName5.Text + "','" + txtName1.Text + "')"
        Dim cmd As OleDbCommand = New OleDbCommand(addUser, conn)
        cmd.ExecuteNonQuery()
        MsgBox("User added successfully")
        '####################################################################
        conn.Close()


Do note that I have many more fields that I "could" enter into this type of a command but I am starting small to avoid any other oddities. Other general notes would be that "Computer" is the name of the table (there are many more included in the database used) and txtName5.txt and Name1.text are just plain text boxes that users can enter data in.



I realize that these ODBC commands can be a real bear to deal with all the " 's so any help would be greatly appreciated and more code can be presented if necessary.
User is offlineProfile CardPM

Go to the top of the page

Jayman
post 10 Oct, 2008 - 09:43 AM
Post #2


Student of Life

Group Icon
Joined: 26 Dec, 2005
Posts: 6,837



Thanked 38 times

Dream Kudos: 500

Expert In: C#, VB.NET, Java

My Contributions


Moved to VB.NET.
User is online!Profile CardPM

Go to the top of the page

Damage
post 10 Oct, 2008 - 01:22 PM
Post #3


D.I.C Addict

Group Icon
Joined: 5 Jun, 2008
Posts: 728



Thanked 7 times

Dream Kudos: 75
My Contributions


your missing a ' by your first value(txtname2)
CODE

" + txtName2.Text + "'
User is offlineProfile CardPM

Go to the top of the page

StrategicBlob
post 17 Oct, 2008 - 06:00 AM
Post #4


New D.I.C Head

*
Joined: 26 Jun, 2008
Posts: 12


My Contributions


QUOTE(Damage @ 10 Oct, 2008 - 02:22 PM) *

your missing a ' by your first value(txtname2)
CODE

" + txtName2.Text + "'




Ah yes indeed, thank you damage! Those stinkin single quotes get me all the time. I am very close but now it is saying "Number of query values and destination fields are not the same.". My gut is telling me I need to include where the variables are going but I am not sure where to declare that.
User is offlineProfile CardPM

Go to the top of the page

rollout369
post 20 Oct, 2008 - 06:49 AM
Post #5


New D.I.C Head

*
Joined: 17 Oct, 2008
Posts: 6

It could be because USER is a reserved SQL keyword. Try changing this column name to something else. I would also avoid slashes in column names.
User is offlineProfile CardPM

Go to the top of the page

StrategicBlob
post 20 Oct, 2008 - 01:04 PM
Post #6


New D.I.C Head

*
Joined: 26 Jun, 2008
Posts: 12


My Contributions


QUOTE(rollout369 @ 20 Oct, 2008 - 07:49 AM) *

It could be because USER is a reserved SQL keyword. Try changing this column name to something else. I would also avoid slashes in column names.



Holy Cow that did the trick!! I thought since the name "User" was in a string it would not matter but that did it! Mucho Thanks for All Who Helped biggrin.gif
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/21/08 10:23AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month