GridView RowUpdating SqlDataSource.Update from CodeBehind

前端 未结 3 1758
借酒劲吻你
借酒劲吻你 2021-01-23 21:17

So I am having an issue with doing an update in a Gridview during an OnRowUpdating event.

What I am trying to do is set the UpdateCommand in an SqlDataSource then update

3条回答
  •  情书的邮戳
    2021-01-23 21:59

    Your UpdateCommand is supposed to be an UPDATE command, not a SELECT command.

    SqlDataSource1.UpdateCommand = "SELECT Something FROM A_Table WHERE ID = " + e.RowIndex;
    

    Change that line to something closer to this:

    SqlDataSource1.UpdateCommand = "UPDATE A_Table SET Something = @Something WHERE ID = " + e.RowIndex;
    

    See this msdn link for more info on how to use the UpdateCommand:

    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.updatecommand.aspx

提交回复
热议问题