I have the strings which consists of ( ' ) quote mark like "mother's love" ...
While inserting the data by sql query from c#. It shows error. How can i rectify the problem and insert this kind of data successfully?
string str2 = "Insert into tblDesEmpOthDetails (EmpID, Interviewnotes) values ('" + EmpId + "','" + Interviewnotes + "')";
Interview notes consists the value like "Mother's love" (with single quote). While executing this query it shows error as "Unclosed quotation mark after the character string ')" how can i insert this type of strings?
I'm pretty sure you don't use SQL parameters:
using (SqlCommand myCommand = new SqlCommand(
"INSERT INTO table (text1, text2) VALUES (@text1, @text2)")) {
myCommand.Parameters.AddWithValue("@text1", "mother's love");
myCommand.Parameters.AddWithValue("@text2", "father's love");
//...
myConnection.Open();
myCommand.ExecuteNonQuery();
//...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With