0

我有 dexpress Xtragrid 并且有未绑定的列,我想将它们保存回 SQL 数据库。如何将结果保存回数据库

    Private unboundValues As New List(Of Integer)()
Private Function GetAllValues(ByVal view As GridView) As List(Of Integer)
    unboundValues.Clear()
    ' Obtain the Unbound column. 
    Dim col As DevExpress.XtraGrid.Columns.GridColumn = view.Columns.ColumnByFieldName("GridColumn1")
    If col Is Nothing Then
        Return unboundValues
    End If
    view.BeginSort()
    Try
        ' Obtain the number of data rows. 
        Dim dataRowCount As Integer = view.DataRowCount
        ' Traverse data rows and change the Price field values. 
        For i As Integer = 0 To dataRowCount - 1
            Dim cellValue As Object = view.GetRowCellValue(i, col)
            unboundValues.Add(DirectCast(cellValue, Integer))
        Next i
    Finally
        view.EndSort()
    End Try
    Return unboundValues
End Function

Private Sub GridView1_rowupdated(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.RowEventArgs) Handles GridView1.RowUpdated
    Dim result1 = GetAllValues(GridView1)
    Dim con As New SqlConnection
    Dim cmd As New SqlCommand
    Try
        con.ConnectionString = "Data Source=" & "server" & " ;Integrated Security=True;Initial Catalog=Test"
        con.Open()
        cmd.Connection = con
        cmd.CommandText = "INSERT INTO testtable (Gridcolumn1) VALUES ('" & Convert.ToString(result1) & "')"
        cmd.ExecuteNonQuery()

    Catch ex As Exception
        MessageBox.Show("Error While inserting record On table..." & ex.Message, "Insert Records")
    Finally
        con.Close()
    End Try

End Sub

当我保存到表中时,我插入 System.Collections.Generic.List`1[System.String] 而不是 result1 中的值

4

0 回答 0