I have a textarea control that passes it's contents to be stored onto an SQL table. I'm running into problems with my SQL Insert command whenever it tries to pass a string from the textarea that includes an apostraphe; like the sentance "I've got a car".
I'm geussing it is because SQL recognizes the apostraphe in "I've" as the end of a column value. Is there an escape character that will tell SQL that the apostraphe is part of the string input?
Loading
bednarjmPosted Jun 15, 2009, 4:22 PM
Niradhip ChakrabortyPosted Jun 15, 2009, 4:22 PM
txtFirstName.Text.Replace("'", "''")
bednarjmPosted Jun 15, 2009, 4:16 PM
1. use parameters with your sql query (the preferred way):
for command object (cmd}
cmd.Paramaters.AddWithValue
2. escape the single ' with a two ''
string sql = "insert into myTable (id, name) values ("abcd","Fred Flint''stone");
Jim B