1
        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();

谢谢!

4

1 回答 1

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);
于 2013-09-19T08:50:33.750 回答