/*
以下代码调用UpdateInStore方法修改记录
但是我这样设计之后,我可空类型的字段的值为空的时候 在UpdateInStore方法中设置值为DBNull 但是这样设置了之后貌似就相当于这个字段为空了吧,所以update语句不会修改这个字段的值,是这样的吧? 但是我的本意是修改这个字段的值为空值
我这样用可空类型是不对的吧?可空类型到底该咋用呢?像我这样用的话感觉还不如不用呢 变得这么麻烦了??郁闷。麻烦各位指点一下吧!
*/ int? number = null;
int? prid = null;
int? pinzhi = null;
int? danwei = null;
decimal? baojia = null;
decimal? shoujia = null;
bool isgood, isbr;
private void button4_Click(object sender, EventArgs e)
{ if (cboxPinZhi.SelectedIndex > -1)
pinzhi = Convert.ToInt32(cboxPinZhi.SelectedValue.ToString());
if (!string.IsNullOrEmpty(txtISGNum.Text.Trim()))
number = Convert.ToInt32(txtISGNum.Text.Trim());
if (!string.IsNullOrEmpty(txtGY.Text.Trim()))
prid = Convert.ToInt32(txtGY.Text.Trim());
if (!string.IsNullOrEmpty(txtSouJia.Text.Trim()))
shoujia = Convert.ToDecimal(txtSouJia.Text);
if (!string.IsNullOrEmpty(txtGIPrice.Text.Trim()))
baojia = Convert.ToDecimal(txtGIPrice.Text); if (chkgood.Checked)
isgood = true;
else
isgood = false;
if (chkbr.Checked)
isbr = true;
else
isbr = false;
string style = "";
if (cboxcolor.SelectedIndex > -1)
style = cboxcolor.SelectedValue.ToString();
if (cboxdanwei.SelectedIndex > -1)
danwei =Convert.ToInt32(cboxdanwei.SelectedValue.ToString());
int success = doperate.UpdateInStore(dropTextBox1.Text, prid, Convert.ToInt32(cboxSName.SelectedValue.ToString()), danwei,
number, baojia, txtISRe.Text.Trim(), pinzhi, xj.Text.Trim(), dj.Text.Trim(), pj.Text.Trim(), gd.Text.Trim(), fz.Text.Trim(), shoujia, style, isbr, isgood,
Convert.ToInt32(dgvISManage.Rows[dgvISManage.CurrentCell.RowIndex].Cells[19].Value.ToString()));
if (success > 0)
{
MessageBox.Show("信息修改成功!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
frmISManage_Load(sender, e);
}
else
MessageBox.Show("修改出错,未能修改成功", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); }//以下代码是UpdateInStore的代码
public int UpdateInStore(string gname, int? pid, int gclass, int? gunit, int? num, decimal? price, string beizhu, int? pinzhi, string xiongjing, string dijing,
string pengjing, string gaodu, string fenzhi, decimal? shoujia, string color, bool isbareroot, bool isgood, int iid)
{
SqlConnection sqlcon = datacon.getcon();
SqlCommand sqlcom = new SqlCommand("proc_updateInStore", sqlcon);
sqlcom.CommandType = CommandType.StoredProcedure;
sqlcom.Parameters.Add("@gname", SqlDbType.VarChar, 50).Value = gname;
if (pid.HasValue)
sqlcom.Parameters.Add("@pid", SqlDbType.Int).Value = pid;
else
sqlcom.Parameters.Add("@pid", SqlDbType.Int).Value = System.DBNull.Value; sqlcom.Parameters.Add("@gclass", SqlDbType.Int).Value = gclass;
if(gunit.HasValue)
sqlcom.Parameters.Add("@gunit", SqlDbType.Int).Value = gunit;
else
sqlcom.Parameters.Add("@gunit", SqlDbType.Int).Value = System.DBNull.Value;
if (num.HasValue)
sqlcom.Parameters.Add("@num", SqlDbType.Int).Value = num;
else
sqlcom.Parameters.Add("@num", SqlDbType.Int).Value = System.DBNull.Value;
if (price.HasValue) sqlcom.Parameters.Add("@price", SqlDbType.Decimal).Value = price;
else
sqlcom.Parameters.Add("@price", SqlDbType.Decimal).Value = System.DBNull.Value;
sqlcom.Parameters.Add("@beizhu", SqlDbType.VarChar, 1000).Value = beizhu;
if (pinzhi.HasValue)
sqlcom.Parameters.Add("@pinzhi", SqlDbType.Int).Value = pinzhi;
else
sqlcom.Parameters.Add("@pinzhi", SqlDbType.Int).Value = System.DBNull.Value;
sqlcom.Parameters.Add("@xiongjing", SqlDbType.VarChar, 50).Value = xiongjing;
sqlcom.Parameters.Add("@dijing", SqlDbType.VarChar, 50).Value = dijing;
sqlcom.Parameters.Add("@pengjing", SqlDbType.VarChar, 50).Value = pengjing;
sqlcom.Parameters.Add("@gaodu", SqlDbType.VarChar, 50).Value = gaodu;
sqlcom.Parameters.Add("@fenzhi", SqlDbType.VarChar, 50).Value = fenzhi;
if (shoujia.HasValue) sqlcom.Parameters.Add("@shoujia", SqlDbType.Decimal).Value = shoujia;
else
sqlcom.Parameters.Add("@shoujia", SqlDbType.Decimal).Value = System.DBNull.Value; sqlcom.Parameters.Add("@color", SqlDbType.VarChar, 20).Value = color;
sqlcom.Parameters.Add("@isbareroot", SqlDbType.Bit).Value = isbareroot;
sqlcom.Parameters.Add("@isgood", SqlDbType.Bit).Value = isgood;
sqlcom.Parameters.Add("@iid", SqlDbType.Int).Value = iid; sqlcon.Open();
int success = 0;
try
{
success = sqlcom.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
sqlcom.Dispose();
sqlcon.Close();
sqlcon.Dispose();
}
return success;
}
解决方案 »
- treeview 选中弹出窗口,关闭弹出窗口再次打开时的问题
- 接口设计,用什么软件画图合适
- C#引用C++外部接口,回调函数问题(高手请入)
- 关于绘图打印的问题 请大家给点建议 谢谢!!!
- 使用VS2005操作串口的类,在一个界面中打开串口,在另一个界面中关闭,出现问题
- 急求键盘事件解决问题
- 如何用C#代码控制word文档目录的自动生成?
- 非牛人物和不懂得数据库的就不要进来了 关于c#读取sqlserver 存储过程游标的问题
- c#照着书上的怎么出错了???
- 为什么我一进行监听程序就“未响应”了?(Socket问题)
- activex中调用exe问题
- 我想用C#写了段动态添加可移动控件的代码但是添加上了不能移动,代码如下
或??