string Sql = "insert into fcfn(cc,date) values(@cc,@date)"; SqlCommand SqlComm = new SqlCommand(Sql, SqlConn);
SqlParameter paramter1 = new SqlParameter("@cc", SqlDbType.VarChar);
paramter1.Value = textbox1.Text;
SqlParameter paramter2 = new SqlParameter("@date", SqlDbType.VarChar);
paramter2.Value = textbox2.Text;
SqlComm.Parameters.Add(paramter1);
SqlComm.Parameters.Add(paramter2);
SqlComm.ExecuteNonQuery();
MessageBox.Show("添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);以上是我写的代码,请各位帮忙看下,错误在哪里,如果 textbox1.Text为空,为什么不能插入数据库表中?谢谢!
if(string.IsNullOrEmpty(textBox1.Text))
{
paramter2.Value = System.DBNull.Value;
}
else
paramter2.Value = textbox2.Text; 数据库 "" 和null是不一样的。