3
.NET:
string userString = textBox1.Text;
string replacedString = userString.Replace("'", "''");
SQL:
replacedString = Replace(userString,"'","''")
Hope this helps.
Accepted 1
Hi Giorgio,
Whenever you have single quotes, replace them with 2 single quotes. That should work.
0
Nainil:
Yes, thank you.
0
Nainil:
Can you give me a sample code of the 2 types?
0
Giorgio,
You can either use .NET string.Replace() method to replace any single quotes with 2 single qoutes or you can use T-SQL's Replace function. Since the value being inserted is passed in as a SqlParameter.Value property, you can run the Replace function through it and ensure that any string being passed to the stored procedure is clean. Hope this helps.
0
Nainil:
Yes, if it was a string. But it will be some text that the user entered. Is there a way to do it automatically when I put it into the sql command to save it?