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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rakrus106 reputationPosted Feb 19, 2008, 10:39 PM EST
Manoj Bisht123 reputationPosted Feb 19, 2008, 11:20 PM EST
Plz explain it........
Rakrus106 reputationPosted Feb 19, 2008, 11:43 PM EST
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 Bisht123 reputationPosted Feb 20, 2008, 1:44 AM EST
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";Niradhip ChakrabortyRank #429 · 5.8K reputationPosted Feb 20, 2008, 9:26 AM EST
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()
Shreeharsha BR34 reputationPosted Feb 10, 2011, 2:52 AM EST
Patel SoniyaRank #7,043 · 250 reputationPosted Dec 1, 2015, 11:14 PM EST
Jignesh TrivediRank #16 · 50.3K reputationPosted Dec 2, 2015, 12:13 AM EST