What is the difference between DataView and DataTable in .Net? As far as I understand DataView is just a false presentation of DataTable. When should I use DataView?
Thanks in advance.
A DataTable object represents tabular data as an in-memory, tabular cache of rows, columns, and constraints. The DataSet consists of a collection of DataTable objects that you can relate to each other with DataRelation objects.
A DataView enables you to create different views of the data stored in a DataTable, a capability that is often used in data-binding applications. Using a DataView, you can expose the data in a table with different sort orders, and you can filter the data by row state or based on a filter expression.
DataTable means single table representation whereas a DataSet is a multiple table representation. That means by using DataTable we can hold only one single table from the database, if we use DataSet we can hold multiple tables at a time... DataView means view of data available in DataSet ...
The DataView class is used to provide a customizable view of DataTable to sort, filter, search, edit, and navigate through the records. To sort and filter records, the RowFilter and Sort properties of the class must be set.
When you want to run a query and show the subset of data in a control, a DataView could help you. That's just one example, look at the MSDN example for DataView, that explains where you should use DataViews with DataTables...
DataTable
A datatable is an in-memory representation of a single database table. You can think of it as having columns and rows in the same way. The DataTable is a central object in the ADO.NET library. Other objects that use the DataTable include the DataSet and the DataView.
Look at MSDN The DataTable class for more details.
DataView
A dataview is a view on a datatable, a bit like a sql view. It allows you to filter and sort the rows - often for binding to a windows form control.
Additionally, a DataView can be customized to present a subset of data from the DataTable. This capability allows you to have two controls bound to the same DataTable, but showing different versions of the data. For example, one control may be bound to a DataView showing all of the rows in the table, while a second may be configured to display only the rows that have been deleted from the DataTable. The DataTable also has a DefaultView property which returns the default DataView for the table.
Look at MSDN DataView class for more details.
DataTable
means single table representation whereas a DataSet
is a multiple table representation.
That means by using DataTable
we can hold only one single table from the database, if we use DataSet
we can hold multiple tables at a time...
DataView
means view of data available in DataSet
...(view of table available in DataSet
) it is used to find a record, sort, filter the record... by using DataView
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With