none
For Loop Performance Issue while Updating Datatable... RRS feed

  • Question

  • I am updating Real time data from Datagrid to Datatable..

    Everything is Working Fine But performance Issue while Pasting 1 Lakh and above  data..

    1. Wpf Datagrid

    2. DatatableModel.GridDatatable.Dt is Datatable

      private static async void CommandBinding_CanExecutePaste(object sender, ExecutedRoutedEventArgs e)
            {
              var datagrid = (DataGrid) sender;
    
                var s = Clipboard.GetText();
                var lines = s.Split('\n');
                var row = (DataGridRow)datagrid.ItemContainerGenerator
                    .ContainerFromItem(datagrid.CurrentCell.Item);
                var rowindex = datagrid.ItemContainerGenerator.IndexFromContainer(row);
                var col = datagrid.CurrentCell.Column.DisplayIndex;
                foreach (var line in lines)
                {
                    if (rowindex < DatatableModel.GridDatatable.Dt.Rows.Count && line.Length > 0)
                    {
                        var cells = line.Split('\t');
                        for (var i = 0; i < cells.GetLength(0); ++i)
                        {
                            if (col + i <DatatableModel.GridDatatable.Dt.Columns.Count)
                            {
                              DatatableModel.GridDatatable.Dt.Rows[rowindex][col + i] = cells[i].TrimEnd();
                            }
                            else
                            {
                                break;
                            }
                        }
                        rowindex++;
                    }
                    else
                    {
                        break;
                    }
                }

    How can i improvise the code to Update Faster.


    • Edited by ID GO Saturday, August 11, 2018 4:25 PM
    Saturday, August 11, 2018 4:24 PM

Answers

  • If you want to speed up performance, then you'll use a collection and a custom type, like a DTO.

    http://lauteikkehn.blogspot.com/2012/03/datatable-vs-list.html

    High performance Web solutions or SOA solutions such as WCF and WebAPI don't use datatable, as an example.

    https://dzone.com/articles/reasons-move-datatables

    https://www.codingblocks.net/programming/boxing-and-unboxing-7-deadly-sins/

    https://www.codeproject.com/Articles/1050468/Data-Transfer-Object-Design-Pattern-in-Csharp

    • Marked as answer by ID GO Wednesday, August 15, 2018 4:14 PM
    Saturday, August 11, 2018 9:04 PM

All replies

  • If you want to speed up performance, then you'll use a collection and a custom type, like a DTO.

    http://lauteikkehn.blogspot.com/2012/03/datatable-vs-list.html

    High performance Web solutions or SOA solutions such as WCF and WebAPI don't use datatable, as an example.

    https://dzone.com/articles/reasons-move-datatables

    https://www.codingblocks.net/programming/boxing-and-unboxing-7-deadly-sins/

    https://www.codeproject.com/Articles/1050468/Data-Transfer-Object-Design-Pattern-in-Csharp

    • Marked as answer by ID GO Wednesday, August 15, 2018 4:14 PM
    Saturday, August 11, 2018 9:04 PM
  • Hi ID GO,

    if you want to past 1 Lakh and above  data, I would suggest that you could consider pagination, which could reduce memory consumption, form render, etc. For more information about WPF datagrid pagination, please refer to:

    https://www.codeproject.com/Articles/1092189/WPF-Pagination-for-DataGrid

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, August 13, 2018 3:30 AM
    Moderator
  • Hi ID GO,

    if you want to past 1 Lakh and above  data, I would suggest that you could consider pagination, which could reduce memory consumption, form render, etc. For more information about WPF datagrid pagination, please refer to:

    https://www.codeproject.com/Articles/1092189/WPF-Pagination-for-DataGrid

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    1. I dont want to split the Grid and Make Page's ....I just need to Boost the Performance in above Code

    Tuesday, August 14, 2018 9:51 PM
  • 1. I dont want to split the Grid and Make Page's ....I just need to Boost the Performance in above Code

    What are you talking about? There is only one form there with a grid on it. The  grid has the ability to access the datasource and show subsets of data from the datasource, as pages aka pagination.

    That's how you give the illusion of speed to the user, becuase all the data is not being loaded into the gird at once. The grid only shows subsets of data loaded into the grid from the datasource as set by the user looking at the data displayed by the grid. 

    Tuesday, August 14, 2018 10:21 PM
  • If you want to speed up performance, then you'll use a collection and a custom type, like a DTO.

    http://lauteikkehn.blogspot.com/2012/03/datatable-vs-list.html

    High performance Web solutions or SOA solutions such as WCF and WebAPI don't use datatable, as an example.

    https://dzone.com/articles/reasons-move-datatables

    https://www.codingblocks.net/programming/boxing-and-unboxing-7-deadly-sins/

    https://www.codeproject.com/Articles/1050468/Data-Transfer-Object-Design-Pattern-in-Csharp

    DA924x: I just Tried ObservableCollection Excellent Performance.....

    Thanks for this Great Suggest....It did wonders for me in Performance...

    Wednesday, August 15, 2018 4:16 PM
  • I am glad it worked out for you.
    Thursday, August 16, 2018 11:21 AM