Label lb = (Label)GridView1.Rows[e.RowIndex].FindControl("Label6");
TextBox tx1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1");
TextBox tx2 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox2");
mycon.Open();
SqlCommand myupdatecommand = new SqlCommand("update Users set(user_name,user_surname) values('"+tx1.Text+"','"+tx2.Text+"') where user_id='"+lb.Text+"'", mycon);
myupdatecommand.ExecuteNonQuery();
GridView1.EditIndex = -1;
GridView1.DataBind();
谢谢!
答案 0 :(得分:0)
第一个更新语句不正确,其次请使用SQL参数以避免SQL注入。
SqlCommand cmd= new SqlCommand("update Users set user_name=@userName,user_surname=@userSurName where user_id=@userID", mycon);
cmd.Parameters.AddWithValue("@userName",yournameTextBox.Text);
cmd.Parameters.AddWithValue("@userSurName",yourSurnnameTextBox.Text);
cmd.Parameters.AddWithValue("@userID",yourID);