【发布时间】:2017-03-26 09:56:19
【问题描述】:
我在仅更新 GridView 中的选中行时遇到了问题,因为我只需要根据选中行的 ID 值更新一个列单元格值。
我试过这段代码,但它更新随机行,而不是检查:
Try
Dim I As Integer
For I = 0 To GridView1.SelectedRowsCount() - 1
If (GridView1.GetSelectedRows()(I) >= 0) Then
Dim strID As String = GridView1.GetRowCellValue(I, "ID")
Dim strUpdate As String = "UPDATE records SET payment_order= @payment_order where ID = @ID"
cmd.CommandType = CommandType.Text
cmd.CommandText = strUpdate.ToString()
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("@payment_order", rfnd_id_lbl.Text)
cmd.Parameters.AddWithValue("@ID", strID)
cmd.Connection = con
con.Open()
cmd.ExecuteNonQuery()
End If
Next
Catch ex As SqlException
Dim errorMsg As String = "Error in Update"
errorMsg += ex.Message
Throw New Exception(errorMsg)
Finally
con.Close()
End Try
谁能帮我解决这个问题?
【问题讨论】: