更新已检查的Gridview行

时间:2017-03-26 09:56:19

标签: vb.net xtragrid

我在更新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

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

尝试使用gridView1.GetDataRow(gridView1.GetSelectedRows()[i])获取应该用于更新参数的选定记录。

我希望它有所帮助。

DX DOC:https://documentation.devexpress.com/WindowsForms/DevExpress.XtraGrid.Views.Base.ColumnView.GetSelectedRows.method