如何在rowupdating命令上更新GridView中的数据 [英] How to update data in gridview on rowupdating command

查看:56
本文介绍了如何在rowupdating命令上更新GridView中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请有人告诉我如何删除行内更新命令代码,即对象引用未设置为对象的实例".

我的代码是

Pls some one tell that how to remove the in row updating command code, which is "Object reference not set to an instance of an object".

my code is

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString);
            SqlCommand cmd = new SqlCommand();
            Label lblstid = (Label)GridView1.Rows[e.RowIndex].FindControl("Id");
            TextBox txtname = (TextBox)GridView1.Rows[e.RowIndex].FindControl("producttype");
            TextBox txtclassname = (TextBox)GridView1.Rows[e.RowIndex].FindControl("img");
            //TextBox txtrollno = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtRollNo");
            //  TextBox txtemailid = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtEmailId");
            //cmd.Connection = con;
            con.Open();
            cmd = new SqlCommand("Update collections set producttype='" + txtname.Text + "',img='" + txtclassname.Text + "'where Id='" + lblstid.Text + "'",con );
            //cmd.CommandText = "Update collections set producttype='" + txtname.Text + "',img='" + txtclassname.Text + "'where Id='" + lblstid.Text + "'";
            //cmd.Connection.Open();
            cmd.ExecuteNonQuery();
            GridView1.EditIndex = -1;
            BindData();




请有人告诉我们如何消除在诸如rowdeleting和rowupdating对象之类的每个事件中引发在命令对象中的错误,因此请帮助我纠正此错误.




pls some one tell that how to remove this error which is throwing in command object, in every event like rowdeleting and rowupdating object, so help me to correct this error.

推荐答案

对象引用未设置为对象的实例"
这仅表示您正在尝试使用null的对象的属性.

您所需要做的就是在该行上放置断点,并查看负责的对象并对其进行处理.使用Visual Studio调试器,它将为您提供帮助.
"Object reference not set to an instance of an object"
This simply means that you are trying to use a property of an object that is null.

All you need is to put breakpoint at that line and see the object responsible and handle the same. Use Visual Studio DEBUGGER, it will help you out.


这篇关于如何在rowupdating命令上更新GridView中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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