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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Thread ID:

Created:

Updated:

Platform:

Replies:

127495 Nov 18,2016 06:27 PM UTC Nov 24,2016 04:49 AM UTC WPF 3
loading
Tags: SfDataGrid
jose
Asked On November 18, 2016 06:27 PM UTC


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

Jai Ganesh S [Syncfusion]
Replied On 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 


jose
Replied On November 23, 2016 05:15 PM UTC

ok tanks jai ganesh!

Jai Ganesh S [Syncfusion]
Replied On 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  


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;