string sql = string.Format("select * from TM_部员情报 where 部员ID = {0}", textBox1.Text);
SqlCommand comm = new SqlCommand(sql, DataBaseSetting.Form1.Conn);
SqlDataAdapter sda = new SqlDataAdapter();
DataTable dt = null;
sda.Fill(dt);
if (dt != null && dt.Rows.Count > 0)
{
comm.CommandText = string.Format("update TM_部员情报 set 部员ID = {0} where 部员ID = {0}", textBox1.Text.Trim());
comm.ExecuteNonQuery();
}
else
{
comm.CommandText = string.Format("insert into TM_部员情报 (部员ID,部员氏名,氏名ガナ,住所,入部日,生年月日,年齢,性别,会社名,会社ガナ,会社住所,会社TEL,备考)values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}')", textBox1.Text.Trim(), textBox2.Text.Trim(), textBox3.Text.Trim(), textBox4.Text.Trim(), textBox5.Text.Trim(), textBox6.Text.Trim(), textBox7.Text.Trim(), comboBox1.Text, textBox8.Text.Trim(), textBox9.Text.Trim(), textBox10.Text.Trim(), textBox11.Text.Trim(), textBox12.Text.Trim());
comm.ExecuteNonQuery();
}
如果textbox里的值存在就更新 ,如果不存在就添加 ,执行以后说我判断值不能为Null ,这哪里错了啊?