protected void gvExample_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string s = gvExample.DataKeys[e.RowIndex].Value.ToString();
TextBox FirstName = gvExample.Rows[e.RowIndex].FindControl("txtFirstName") as TextBox;
TextBox LastName = gvExample.Rows[e.RowIndex].FindControl("txtLastName") as TextBox;
TextBox Title = gvExample.Rows[e.RowIndex].FindControl("txtTitle") as TextBox;
TextBox Country = gvExample.Rows[e.RowIndex].FindControl("txtCountry") as TextBox;
string query ="UPDATE USER_DETAILS SET LAST_NAME='" + LastName.Text + "',FIRST_NAME='" + FirstName.Text + "',TITle='" + Title.Text + "',COUNTRY='" + Country.Text + "'";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlconnection"].ConnectionString);
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
gvDatabind();
}
The values are not updating. They are updating as lastname.Text firstname.Text. Please help me.
It sounds like your variables
FirstNameetc are not being cast asTextBoxproperly... What if you try something like the following castObviously also including a WHERE clause and
int.parsethe Id value for that and generally making the example code you've shown more production ready.