We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

hi, How can I store data from a datagrid to a datatable?


Hi. I have a grid. Which allows me to add to the same data from new row. But when I want to send them to store does not allow me to go through the whole datagrid to extract one by one the data. The truth is I do not know how to read the rows inside the datagrid.

my code is.

   <syncfusion:SfDataGrid
                        Name="Grid_ordenes_compra"
                        Grid.Row="1"
                        Grid.Column="0"
                        AutoGenerateColumns="False"
                        GroupDropAreaText="Separe por numero Orden de Compra"
                        ItemsSource="{Binding}"
                        ShowGroupDropArea="True">
                        <syncfusion:SfDataGrid.Columns>
                            <syncfusion:GridTextColumn
                                HeaderText="id"
                                IsHidden="True"
                                MappingName="id_order" />
                            <syncfusion:GridTextColumn
                                Width="100"
                                AllowGrouping="True"
                                HeaderText="OC"
                                MappingName="Orden_compra_numero" />
                            <syncfusion:GridTextColumn
                                Width="150"
                                HeaderText="Tipo"
                                MappingName="tipo_orden_compra" />
                            <syncfusion:GridTextColumn
                                Width="150"
                                HeaderText="Equipo"
                                MappingName="modelo" />
                            <syncfusion:GridTextColumn
                                Width="200"
                                HeaderText="Cliente"
                                MappingName="cliente" />
                            <syncfusion:GridTextColumn
                                Width="200"
                                HeaderText="Fecha"
                                MappingName="fecha" />
                            <syncfusion:GridTextColumn
                                Width="200"
                                HeaderText="Nº Serie"
                                MappingName="nserie" />
                            <syncfusion:GridTextColumn
                                Width="200"
                                HeaderText="A.W.H"
                                MappingName="AWH" />
                            <syncfusion:GridTextColumn
                                Width="200"
                                HeaderText="In House"
                                MappingName="INH" />
                        </syncfusion:SfDataGrid.Columns>
                    </syncfusion:SfDataGrid>

and i need save using this code


 If tblconfig.Rows.Count > -1 Then
            For Each row As Data.DataRow In tblconfig.Rows
                mara = id_nuevo_configuracion()
                cnn.con.Open()
                code = CStr(row("codigo"))
                count = CStr(row("cantidad"))
                des = CStr(row("descripcion"))
                sql = "insert into OC_Configuracion(id, codigo, descripcion, cantidad, id_order) values ('" & mara & "', '" & code & "', '" & des & "', '" & count & "', '" & order & "' )"
                Dim cmd As New SqlCommand(sql, cnn.con)
                Dim rest As Integer
                rest = cmd.ExecuteNonQuery
                If rest > 0 Then
                    counter = counter + 1
                    rest = 0
                End If
                cnn.con.Close()
            Next
            tblconfig.Clear()

but tblconfig is my datatable.  But I can not go from the datagrid called configuracionnes to the datatable called tblconfig. every code is in vb.net

3 Replies

JG Jai Ganesh S Syncfusion Team November 21, 2016 09:38 AM UTC

Hi jose, 
You can read the rows inside the DataGrid when  the ItemsSource is DataTable by using the following code, 
Private Sub Button_Click(sender As Object, e As RoutedEventArgs) 
    For Each item As RecordEntry In datagrid.View.Records 
        Dim data = TryCast(item.Data, DataRowView) 
 
        Dim row = data.Row 
        Dim name = row("Name") 
        Dim title = row("Title") 
        Dim contactID = row("ContactID") 
        Dim birthDate = row("BirthDate") 
        Dim gender = row("Gender") 
    Next 
 
End Sub 
 
Regards, 
Jai Ganesh S 



JO jose November 23, 2016 05:15 PM UTC

ok tanks jai ganesh!


JG Jai Ganesh S Syncfusion Team November 24, 2016 04:49 AM UTC

Hi jose,  
Thank you for the update. 
Please let us know if you need further assistance on this. 
Regards, 
Jai Ganesh S  


Loader.
Live Chat Icon For mobile
Up arrow icon