single quotes escape during string insertion into a database single quotes escape during string insertion into a database database database

single quotes escape during string insertion into a database


Try this

    string sql= "insert into gtable (1text,1memo) values (@col1,NULL)";    OleDbCommand cmd = new OleDbCommand(sql, con);    cmd.Parameters.AddWithValue("@col1",textBox3.Text);    con.Open();


try

string sql= "insert into gtable (1text, 1memo) " +             "values ('" + textBox3.Text.Replace("'", "''") + "', null)";


To insert single quotes in database replace ' with ''. In database only single quote will go.

Use this

string sql= "insert into gtable (1text,1memo) values ('"             + textBox3.Text.Replace("'", "''") + "', null)";

Rest code is same.