I wriiten a insert query in C# and it works fine.But when i am trying to insert character like ' then its throwing exception.
Please let me know the correct way so that it should accept all characters.
Thanks
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Mar 19, 2012, 2:42 AM
please try
insert into tablename values('"+textbox1.text.Replace("'","''")
+"','"+textbox2.text.Replace("'","''")
+"');
Replece you single quote to two single quote.
hope this help.
SenthilkumarPosted Mar 18, 2012, 2:42 AM
INSERT INTO Example(Name,Address) VALUES('YYY''s',50)
Based on that, you can workaround in asp.net
charbel ghattasPosted Mar 17, 2012, 2:11 PM
for insert character you should follow like
insert into tablename values('aaa','bbb');
while getting control value you should write like
insert into tablename values('"+textbox1.text+"','"+textbox2.text+"');
wat will happen if the value of textbox1 is like ABCD's then while inserting it will be like 'ABCD's' and will throw exception.
if textbox1.text = ABCD's
then u can use this :
insert into tablename values('"+Regex.Replace(textbox1.text, "'", "''")+"','"+textbox2.text+"');
Apurva MehtaPosted Oct 11, 2010, 12:29 AM
Gomathi PalaniswamyPosted Oct 11, 2010, 12:23 AM
for insert character you should follow like
insert into tablename values('aaa','bbb');
while getting control value you should write like
insert into tablename values('"+textbox1.text+"','"+textbox2.text+"');