SqlConnection con = new SqlConnection("...");
con.Open();
string m = "insert into table2 values('"+richTextBox1.Rtf+"')";
SqlCommand ca = new SqlCommand(m, con);
ca.ExecuteNonQuery();
ca = new SqlCommand("select * from table2", con);
SqlDataReader reader = ca.ExecuteReader();
while (reader.Read())
{
richTextBox1.SelectRtf= reader.GetValue(1).ToString();
}
con.Close();为什么一直报有语法错误?
con.Open();
string m = "insert into table2 values('"+richTextBox1.Rtf+"')";
SqlCommand ca = new SqlCommand(m, con);
ca.ExecuteNonQuery();
ca = new SqlCommand("select * from table2", con);
SqlDataReader reader = ca.ExecuteReader();
while (reader.Read())
{
richTextBox1.SelectRtf= reader.GetValue(1).ToString();
}
con.Close();为什么一直报有语法错误?
string m = "insert into table2(字段名) values('"+richTextBox1.Rtf+"')";
richTextBox1.Rtf.Replace("\"", "\"\"");你可以把SQL语句打印出来
用SQL查询分析器调试先看看是什么错误
.NET Framework 类库
SqlDataReader.GetString 方法
获取指定列的字符串形式的值。
那就这样,一个单引号换成两个
richTextBox1.Rtf.Replace("'", "''");