Dataview overhead

test code 1 Reputation point
2021-08-03T09:43:17.373+00:00

Microsoft Link - https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/dataview-performance?redirectedfrom=MSDN%22
states - "DataView constructs an index. An index contains keys built from one or more columns in the table or view."

  1. Is similar option present in dataTable?
  2. Whether DataView creation has any overhead?
  3. Instead of creating New DataView using the dataTable.DefaultView has any benefit? (in terms of dataview creation/memory overhead)
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,264 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,611 Reputation points
    2021-08-04T02:15:43.773+00:00

    Hi testcode-2745,

    1. To index a DataTable, you need to specify an array of DataColumns, which form the unique key of the records in the DataTable.
      More details you can refer to this document.
    2. Creating a new DataView object may consume a lot of resources.
      A DataView provides a dynamic view of data in the underlying DataTable. And DataView also provides you with a dynamic view of a single set of data, much like a database view, to which you can apply different sorting and filtering criteria.
    3. There are two ways to create a DataView. You can use the DataView constructor, or you can create a reference to the DefaultView property of the DataTable.
      When you create a data view through the constructor, you can provide any initial sorting or filtering criteria through the constructor parameters to achieve the best performance when you create the data view. Creating a DataView without specifying sorting or filtering conditions, and then setting the Sort, RowFilter, or RowStateFilter properties will cause the index to be built at least twice.
      Here is a related document.
      Best Regards,
      Daniel Zhang

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments