dataview or datatable

  • Thread starter Thread starter JohnE
  • Start date Start date
J

JohnE

I am working with a gridview and the data is from sql2008 using a stored proc
(soon to be a view). What I would like to know (albeit after the fact) is it
better to use a DataTable or a DataView for retrieving the information? Plus
and Minus of each if possible. Links are good, too.
Thanks.
JE
 
Datatable for storing data and data view for displaying it.

datatables can mirror your database tables and can be linked the same way
they are in the database, you can also save a datatable to the database. so
talking to the database you should use datatable, in fact I never knew you
could use dataview.
but for displaying data datataview has advantages such as sorting
 
I am working with a gridview and the data is from sql2008 using a stored proc
(soon to be a view).  What I would like to know (albeit after the fact)is it
better to use a DataTable or a DataView for retrieving the information? Plus
and Minus of each if possible.  Links are good, too.
Thanks.
JE

DataTable is to store the physical data,
DataView is to view that data.

A major function of the DataView is to allow for data binding.
Additionally, a DataView can be customized to present a subset of data
from the DataTable. This capability lets you have two controls bound
to the same DataTable, but that show different versions of the data.
For example, one control might be bound to a DataView that shows all
the rows in the table, and a second might be configured to display
only the rows that have been deleted from the DataTable. The DataTable
also has a DefaultView property. This returns the default DataView for
the table. For example, if you want to create a custom view on the
table, set the RowFilter on the DataView returned by the DefaultView.

All this means that when you have a DataTable and you need to sort or
filter it, use a DataView. Otherwise, use DataTable

http://msdn.microsoft.com/en-us/library/system.data.dataview.aspx
http://dotnetperls.com/dataview-usage
 
Back
Top