如何解决这个错误:UpdateParameters [英] how slove this error:UpdateParameters

查看:667
本文介绍了如何解决这个错误:UpdateParameters的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何解决这个问题

how to slove this problam

if (e.CommandName == "Update")
      {
          GridViewRow gvrow = (GridViewRow)((ImageButton)e.CommandSource).NamingContainer;
          TextBox txtbarndFaName = (TextBox)gvrow.FindControl("TFBrandFaNameedit");
          TextBox txtbarndEnName = (TextBox)gvrow.FindControl("TFBrandEnNameedit");
          DropDownList txttypepartEnName = (DropDownList)gvrow.FindControl("DDTypehardware");
          int a = int.Parse(txttypepartEnName.SelectedValue);
          SqlDupdate.UpdateParameters["FBrandFaName"].DefaultValue = txtbarndFaName.Text;
          SqlDupdate.UpdateParameters["FBrandEnName"].DefaultValue = txtbarndEnName.Text;
       SqlDupdate.UpdateParameters["FPartCatID"].DefaultValue = txttypepartEnName.SelectedValue.ToString();

          SqlDupdate.Update();
      }



此错误:
System.NullReferenceException:对象引用未设置为对象的实例.

DropDownList txttypepartEnName =(DropDownList)row.FindControl("DDTypehardware

db的类型为smallint.
如何转换SqlDupdate.UpdateParameters ["FPartCatID"].DefaultValue = txttypepartEnName.SelectedValue.ToString();

到int.



this error:
System.NullReferenceException: Object reference not set to an instance of an object.

DropDownList txttypepartEnName = (DropDownList)row.FindControl("DDTypehardware

the type filed db is smallint.
how to convert SqlDupdate.UpdateParameters["FPartCatID"].DefaultValue = txttypepartEnName.SelectedValue.ToString();

to int.

推荐答案

在进入更新之前检查控件是否为null.网格中可能存在一行控件为null的行,因此txttypepartEnName在某些时候为空.
Check if your control is null before moving into the update.Its possible there is a row in your grid with a control that is null, so txttypepartEnName is null at some point.


这篇关于如何解决这个错误:UpdateParameters的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆