I was just trying out this simple code to edit the gridview but it is giving an exception at Line 11 i.e. at cmd.ExecuteNonQuery(). I m not able to understand the problem. Please Help.
Code -
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
int i = Convert.ToInt32(((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text);
int age = Convert.ToInt32(((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text);
string std = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
SqlCommand cmd = new SqlCommand("updata student set age =" + age + ", standard = '" + std + "' where stidid = " + i, scon);
scon.Open();
cmd.ExecuteNonQuery();
GridView1.EditIndex = -1;
scon.Close();
Bind();
}
catch (Exception ex)
{
Response.Write(ex);
}
Jayant Shelk...
0 Points
2 Posts
Error in GridView_Rowediting
Dec 18, 2012 06:40 AM|LINK
Hi,
I was just trying out this simple code to edit the gridview but it is giving an exception at Line 11 i.e. at cmd.ExecuteNonQuery(). I m not able to understand the problem. Please Help.
Code -
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { int i = Convert.ToInt32(((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text); int age = Convert.ToInt32(((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text); string std = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text; SqlCommand cmd = new SqlCommand("updata student set age =" + age + ", standard = '" + std + "' where stidid = " + i, scon); scon.Open(); cmd.ExecuteNonQuery(); GridView1.EditIndex = -1; scon.Close(); Bind(); } catch (Exception ex) { Response.Write(ex); }Jayant Shelke
Mandeep Joon
Participant
1570 Points
386 Posts
Re: Error in GridView_Rowediting
Dec 18, 2012 08:15 AM|LINK
Hi Jayant,
Check this http://hightechnology.in/gridview-edit-delete-update/
Mark this as answer if it is useful.
Mandeep Joon
Blog:- Hightechnology.
Jayant Shelk...
0 Points
2 Posts
Re: Error in GridView_Rowediting
Dec 18, 2012 01:37 PM|LINK
Thank You. Its Working.
Jayant Shelke