srinath

srinath

  • NA
  • 144
  • 0

GridView Rowupdating event

Jun 17 2010 1:36 AM
hi,

I am trying to update the row using gridview_rowupdating  event  but I am unable to update. I tried the code like this...


    foreach (GridViewRow i in GridView1.Rows)
        {
            TextBox sname = i.FindControl("sname") as TextBox;
            TextBox fname = i.FindControl("fname") as TextBox;
            TextBox sex = i.FindControl("txtsex") as TextBox;
     //     Label lblpin1 = i.FindControl("lblpin") as Label;
            TextBox tpin = i.FindControl("txtpin") as TextBox;
            tpin.Enabled = true;
           
       //  lblpin1.Enabled = true;
            string pinno;
            pinno = Convert.ToString(tpin.Text.Trim());           
            conn2.Open();
            SqlCommand cmd = new SqlCommand("update NRDetails2010 set SNAME='" + sname + "',FNAME='" + fname + "',SEX='" + sex + "' where pin='" + pinno.Trim() + "' and  InstCode='" + Session["UId"] + "' and Sem='" + ddlsem.SelectedItem.Text + "' and scheme='" + ddlscheme.SelectedItem.Text.Trim() + "' ", conn2);
            cmd.ExecuteNonQuery();
            conn2.Close();
}

I am getting error at cmd.ExecuteNonQuery()

Here I am giving connection globally and opening in this event.
In gridview, I am updating 3 fields depending on 4 conditions.

please solve my problem.

Answers (1)