Ankita Singh

Ankita Singh

  • NA
  • 159
  • 18.8k

update data in control through gridview

Mar 24 2018 1:08 AM
hello guys...  i was show data in textbox control and dropdown control click edit button in gridview after show data i want to update it.. i am showing my code
try
{
string qry = "update City_tbl set State=@State,City =@City where id=@id";
SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand(qry, con);
cmd.Parameters.AddWithValue("@State", SqlDbType.NVarChar).Value = ddlstate.Text.Trim();
cmd.Parameters.AddWithValue("@City", SqlDbType.NVarChar).Value = TextBox1.Text.Trim();
con.Open();
cmd.ExecuteNonQuery();
con.Close();
FillGrid();
ClearControls();
lblMessage.Text = "Updated Successfully.";
 
}
catch
{
}
finally
{
if (con.State == ConnectionState.Open)
con.Close();
}
when i use breakpoint and debug then connectionis open but not close and  not bind FillGrid()  after this data is not updating... please some one tell me where is problem creating... thank you

Answers (9)