inserting ' into a record, then searching on it

  • Thread starter Thread starter Joe_Black
  • Start date Start date
J

Joe_Black

Hi all,

Using Access 2003, Visual studio.net 2003

I want to allow a user to insert an apostrophe into a text field within
a database, the problem is I get an error when I do this via ado.net,
also if I directly type the text into the field within the table with
the apostrophe in it, then use the data in that field to perform a
search on another table I get an error about a badly formed SQL
statement i.e.

Data in field = "user can't move"

SQL search = "select * from atable where afield = 'user can't move'"

the database see's the apostrophe within the can't as the end of the
text to search on.

I was wondering is the a simple way to get around this problem, my
client seems to love using the apostophe :-). Or do I have to take every
string, parse it for the apostrophe character, then add the backslash
character before it to indicate that it truly is an apostrophe within
the text and not a text delimeter for the SQL statement. this ways seems
a bit long winded for something so simple.

Also is this the only way to insert the apostrophe character into a
field via ado.net?

TIA

Joe
 
Hello joe,
your problem has already been answered on this forum.
You should use comand objects and parameters.
Here you will find a sample code :
http://oraclevsmicrosoft.blogspot.com/2005/03/quotes-parameters.html
It is Oracle oriented,For sql Server you should replace "?" by
"@myparameter"

hope this helps


http://oraclevsmicrosoft.blogspot.com


Joe_Black said:
Hi all,

Using Access 2003, Visual studio.net 2003

I want to allow a user to insert an apostrophe into a text field within
a database, the problem is I get an error when I do this via ado.net,
also if I directly type the text into the field within the table with
the apostrophe in it, then use the data in that field to perform a
search on another table I get an error about a badly formed SQL
statement i.e.

Data in field = "user can't move"

SQL search = "select * from atable where afield = 'user can't move'"

the database see's the apostrophe within the can't as the end of the
text to search on.

I was wondering is the a simple way to get around this problem, my
client seems to love using the apostophe :-). Or do I have to take every
string, parse it for the apostrophe character, then add the backslash
 
oraclevsmicrosoft said:
Hello joe,
your problem has already been answered on this forum.
You should use comand objects and parameters.
Here you will find a sample code :
http://oraclevsmicrosoft.blogspot.com/2005/03/quotes-parameters.html
It is Oracle oriented,For sql Server you should replace "?" by
"@myparameter"

hope this helps


http://oraclevsmicrosoft.blogspot.com

Hi there,

Thanks, that seems like what I'm after, I thought it would be a common
question, but I tried googling for it and couldn't find anything, I
think my search may have been lacking.

Many thanks

Joe
 
Back
Top