Step 1: Don't do this. Use a parameterized query instead.
Parameterized queries remove most of the risk associated with SQL injection attacks.
From the link:
private void CallPreparedCmd() {
string sConnString =
"Server=(local);Database=Northwind;Integrated Security=True;";
string sSQL =
"UPDATE Customers SET City=@sCity WHERE CustomerID=@sCustomerID";
using (SqlConnection oCn = new SqlConnection(sConnString)) {
using (SqlCommand oCmd = new SqlCommand(sSQL, oCn)) {
oCmd.CommandType = CommandType.Text;
oCmd.Parameters.Add("@sCustomerID", SqlDbType.NChar, 5);
oCmd.Parameters.Add("@sCity", SqlDbType.NVarChar, 15);
oCn.Open();
oCmd.Prepare();
oCmd.Parameters["@sCustomerID"].Value = "ALFKI";
oCmd.Parameters["@sCity"].Value = "Berlin2";
oCmd.ExecuteNonQuery();
oCmd.Parameters["@sCustomerID"].Value = "CHOPS";
oCmd.Parameters["@sCity"].Value = "Bern2";
oCmd.ExecuteNonQuery();
oCn.Close();
}
}
}
That being said, you can insert quotes into a string by escaping the double quotes like this:
string newstring = " \"I'm Quoted\" ";