我的表单有几项,在插入时,若没有插入,则默认是0,请问代码需要怎么修改,若不能修改,则提示请填写具体数值也可,代码与截图(红框标注的)如下,谢谢;
try
{
string SqlString = @"INSERT INTO [dbo].[w_prohourcount]
(date,workshop,teams,banci,process,batchNo,probatchNo,proname,spec,unit,daypro,sumpro,state,pax,ulh,note)
values
(@date,@workshop,@teams,@banci,@process,@batchNo,@probatchNo,@proname, @spec,@unit,@daypro,@sumpro,@state,@pax,@ulh,@note)";
SqlCommand comm = new SqlCommand(SqlString, Conn);
comm.Parameters.AddWithValue("@date", inputdate);
comm.Parameters.AddWithValue("@workshop", inputworkshop);
comm.Parameters.AddWithValue("@teams", inputteams);
comm.Parameters.AddWithValue("@banci", inputbanci);
comm.Parameters.AddWithValue("@process", inputprocess);
comm.Parameters.AddWithValue("@batchNo", inputbatchNo);
comm.Parameters.AddWithValue("@probatchNo", inputprobatchNo);
comm.Parameters.AddWithValue("@proname", inputproname);
comm.Parameters.AddWithValue("@spec", inputspec);
comm.Parameters.AddWithValue("@unit", inputunit);
comm.Parameters.AddWithValue("@daypro", inputdaypro);
comm.Parameters.AddWithValue("@sumpro", inputsumpro);
comm.Parameters.AddWithValue("@state", inputstate);
comm.Parameters.AddWithValue("@pax", inputpax);
comm.Parameters.AddWithValue("@ulh", inputulh);
comm.Parameters.AddWithValue("@note", inputnote);
comm.ExecuteNonQuery();
MessageBox.Show("数据保存成功!");
}
catch (Exception ex)
{
// 显示保存失败的错误信息
MessageBox.Show("保存失败:" + ex.Message);
}
finally
{
// 关闭数据库连接
Conn.Close();
}
}
在添加参数前判断下,为空放个0呗
直接在数据库建表的时候设置这个字段默认值为0即可
代码里就不管它,自动就是0了。
好的,我试一下,谢谢