Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT Statement

Status
Not open for further replies.

WoodyRoundUp

Programmer
Feb 28, 2001
187
AU
Hi guys.
I have a question.
I am using VB to write a program, where I will be using an SQL Statement to Insert Data into Table.
But, in the my SQL String, there are fields with a single quote (for example: Jack's)
But the Access Jet Engine will read it differently. and error happens.
Is there any way solve?

Anyway my sql string looks like this:
SQLStr = "INSERT INTO myTable VALUES ('" + myVariable.Text + "')"

while in the myVariable.Text = "Jack's"

the error is from the myVariable.Text.

Please help.
Thanks.
 


Think there is some confusion with '

print sqlstr
INSERT INTO myTable VALUES ('Jack's')

You probably need
SQLStr = "INSERT INTO myTable VALUES (""" + myVariable.Text + """)"

So:

print sqlstr
INSERT INTO myTable VALUES ("Jack's")


I try to keep everything in queries when possible so to avoid this (and other) problems (and it is so easy to call a query). Not sure what the general view on this is.

Stew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top