Storing special character(s) in SQL Server through ASP.NET
I've a TextBox in which i enters Name like Jame's and then i click on submit button. But it throws error Incorrect syntax near 's'. Unclosed quotation mark before the character string '
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 Dec 2, 2015, 5:13 AM
Patel SoniyaPosted Dec 2, 2015, 4:14 AM
Shreeharsha BRPosted Feb 10, 2011, 7:52 AM
Niradhip ChakrabortyPosted Feb 20, 2008, 2:26 PM
By default it wont take '. U need to replace it by ' ' while storing into database but dont worry it will store the ' only.
Use the following code:
Say u want customer name should accept '. like peter's.So the time of saving use the following convertion in your pagebehind class(.aspx).
txtCustomerName.Text.Replace(" ' ", " ' ' ").Trim()
Manoj BishtPosted Feb 20, 2008, 6:44 AM
Thnx Rakrus for your reply.
But still it's not working properly. Here i'm giving my code
string
name=Server.HtmlEncode(txtName.Text); string strsql="Update Rough Set Name='"+name.ToString()+"' Where Active=1";RakrusPosted Feb 20, 2008, 4:43 AM
string strTxtVal=Server.HtmlEncode(TextBox1.Text);
use the above encoded value to insert into database.
While retrieving the save value from database you need to decode it and set it to textbox.
TextBox1.Text=Server.HtmlDecode(encoded textbox value (i.e value from database))
I think you got it.
Manoj BishtPosted Feb 20, 2008, 4:20 AM
Plz explain it........
RakrusPosted Feb 20, 2008, 3:39 AM