Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to store special characters like > < ' " ; in sql server.

I am using like below:

cmd.Parameters.Add("@Message", SqlDbType.VarChar, 50).Value = Server.HtmlEncode(txtBIAttenNurse.Text.Trim().Replace("'", "''"));


For ex: i give a>b - it show in output a>b.

Pls explain
what data type can use?
what type of query can use?
how to store?
how to retrieve?
Posted
Comments
[no name] 5-Feb-15 5:03am    
Hi,

You can use the NVARCHAR data type to store the special characters. While inserting the data into the database table you need to Use the following format. "N'your data here'".

In the above example you can see only a prefix "N" before your data. This will allow you to save the special characters into the database table.

1 solution

You can use Var-char/text datatype to store this type of characters in sqlDB.
i think you are decoding the output when fetching from database using HtmlDecode() method.

e.g: Want to insert data like: a>b
C#
cmd.Parameters.Add("@Message", SqlDbType.VarChar, 50).Value = Server.HtmlEncode(txtBIAttenNurse.Text.Trim().Replace("'", "''"));

your code is fine for data insertion.
but when you are fetching the data then be careful what you really want to showing.

if you want to show like a>b then use HtmlDecode() otherwise use plain text.no need to decode the output.

see here.
https://msdn.microsoft.com/en-us/library/hwzhtkke(v=vs.110).aspx[^]
https://msdn.microsoft.com/en-us/library/ms525347(v=vs.90).aspx[^]
http://www.dotnetperls.com/htmlencode-htmldecode[^]
 
Share this answer
 
Comments
Member 10361286 7-Feb-15 2:49am    
I am using the following code for retrieve field

txtBIAttenNurse.Text = Server.HtmlDecode(dr["BI_AttenNurse"].ToString());

But, How can i receive this field to show in gridview?
i am facing the following issue,while save a less than b in symbol.
/\jmot 7-Feb-15 4:04am    
bind it to the grid view using a template Field.
Member 10361286 7-Feb-15 4:39am    
can i use BoundField?
/\jmot 7-Feb-15 4:45am    
i think, no, because you wanna use Server.HtmlDecode(dr["BI_AttenNurse"].ToString());
Member 10361286 7-Feb-15 5:13am    
can u send small sample .aspx & .cs page with clear details?

how to insert , view , display in grid & others

Email: mdabusiddiq@gmail.com

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900