Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 244,291 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 940 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
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
+Quote Post


Jayman
RE: Access Insert Syntax Error....doh!
10 Oct, 2008 - 09:43 AM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 8,063



Thanked: 159 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Moved to VB.NET.
User is online!Profile CardPM
+Quote Post

Damage
RE: Access Insert Syntax Error....doh!
10 Oct, 2008 - 01:22 PM
Post #3

D.I.C Addict
Group Icon

Joined: 5 Jun, 2008
Posts: 947



Thanked: 13 times
Dream Kudos: 75
My Contributions
your missing a ' by your first value(txtname2)
CODE

" + txtName2.Text + "'

User is offlineProfile CardPM
+Quote Post

StrategicBlob
RE: Access Insert Syntax Error....doh!
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
+Quote Post

rollout369
RE: Access Insert Syntax Error....doh!
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
+Quote Post

StrategicBlob
RE: Access Insert Syntax Error....doh!
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
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 03:57PM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month