hello,
I have used a GridView to edit and update a row.
I have produced the code below
However i get an error as below
I have underlined the place where i get the error
"NullRefere nce Exception was handled near the code"
What's the error and how to rectify it
thanks
I have used a GridView to edit and update a row.
I have produced the code below
However i get an error as below
I have underlined the place where i get the error
"NullRefere nce Exception was handled near the code"
Code:
protected void GridView2_RowUpdating(object sender,GridViewUpdateEventArgs e)
{
String S1;
SqlConnection MyCon = new SqlConnection("Server=HEMA\\SQLEXPRESS;Integrated Security=SSPI;database=demo");
MyCon.Open();
ImageButton b1 = new ImageButton();
TextBox t1 = new TextBox();
TextBox t2 = new TextBox();
foreach (GridViewRow gv in GridView2.Rows)
{
b1 = (ImageButton)gv.FindControl("imagebutton1");
t1 = (TextBox)gv.FindControl("TextBox1");
t2 = (TextBox)gv.FindControl("TextBox2");
[U] if (b1.CommandName == "Update")[/U]
{
S1 = "update t1 set name='" + t2.Text + "' where id=" + t1.Text + "";
SqlCommand UpdateCmd = new SqlCommand(S1, MyCon);
Response.Write("updated");
UpdateCmd.ExecuteNonQuery();
}
}
MyCon.Close();
}
thanks
Comment