Click here to Skip to main content
15,922,155 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
i am getting a value from a table and displaying it in a label, then inserting the label.text into a table in the database.

This is what the label displays:
AFCO FLUTED ROUND WRAP COLUMNS 6"X10' W/ SPLIT C&B

which is correct, but when i insert the label.text to database it looks like this:
AFCO FLUTED ROUND WRAP COLUMNS 6quot;X10' W/ SPLIT Camp;B

its converting the text to raw? why is this? and how can i fix it?
Posted

1 solution

It isn't converting to "raw". It is encoding your text so that your query doesn't break.
I'm guessing your using a query something like
C#
var query = "INSERT INTO YourTable ... VALUES( " + yourValue + ")";

You should be using a paramatarized query where this will be taken care of.
C#
command.CommandText = "INSERT INTO YourTable ... VALUES( @yourValue )"; 
command.Parameters.AddWithValue("@yourValue", yourValueFromLabel);
 
Share this answer
 
v2
Comments
PTG.Jake 17-Oct-12 15:49pm    
Marcus, I tried that, but it still enters into the table encoded text.
fjdiewornncalwe 17-Oct-12 16:20pm    
If that is the case then I'm guessing if you debug the code where you pull the value from the table to insert into the label, you are going to see that encoded quote in there already. You may want to run the value through HtmlDecode first then.

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