GridView RowUpdating问题 [英] GridView RowUpdating Problem
本文介绍了GridView RowUpdating问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到Null引用异常。
I'm getting Null reference exception.
protected void gvDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
Label s_no = (Label)gvDetails.Rows[e.RowIndex].FindControl("s_no");
TextBox project_name =(TextBox)gvDetails.Rows[e.RowIndex].FindControl("project_name");
TextBox r_name = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("r_name");
TextBox rel_start_date=(TextBox)gvDetails.Rows[e.RowIndex].FindControl("Release_start_date");
TextBox rel_end_date =(TextBox)gvDetails.Rows[e.RowIndex].FindControl("Release_EndDate");
con.Open();
MySqlCommand cmd = new MySqlCommand("update lut_release_name1 set project_name='" + project_name.Text + "',r_name='" + r_name.Text + "',Release_start_date='" + rel_start_date.Text + "',Release_EndDate='" + rel_end_date.Text + "' where s_no=" + Convert.ToInt32(s_no.Text), con);
cmd.ExecuteNonQuery();
gvDetails.EditIndex = -1;
con.Close();
BindEmployeeDetails();
}
推荐答案
您没有定义Connection对象,而是尝试打开和关闭连接。实例化适当的对象并为其指定正确的值。
You don't have a Connection object defined and you are trying to open and close a connection. Instantiate the proper object and assign it its proper values.
SqlConnection con= new SqlConnection("your connections string");
我想你需要这样做: -
I guess you need to do this:-
protected void gvDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
SqlConnection con = new SqlConnection(@ data source =connection;初始目录=数据库名称;插入安全性= true);
con.open();
------- - 您的代码-----------------
con.Close();
}
SqlConnection con =new SqlConnection("@data source="connection"; initial catalog=database name; intigrated security=true");
con.open();
-------- Your Code-----------------
con.Close();
}
控制名称错误导致NullReferenceException。
Control name was wrong that leads to the NullReferenceException.
这篇关于GridView RowUpdating问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文