Difference
between DataTable and DataSet
-
S.No DataTable DataSet 1 Meaning:A DataTable is an in-memory representation of a single database table which has collection of rows and columns.Meaning:A DataSet is an in-memory representation of a database-like structure which has collection of DataTables.2 Number of rows retrieved at a time:DataTable fetches only one TableRow at a timeNumber of rows retrieved at a time:DataSet can fetch multiple TableRows at a time3 Provision of DataRelation Objects:As DataTable is a single database table, so there is no DataRelation object in it.Provision of DataRelation Objects:In DataSet, DataTable objects can be related to each other with DataRelation objects.4 Enforcing Data Integrity:In DataTable, there is no UniqueConstraint and ForeignKeyConstraint objects available.Enforcing Data Integrity:In DataSet, data integrity is enforced by using the UniqueConstraint and ForeignKeyConstraint objects.5 DataSource can be Serialized or Not:In DataTable, DataSource cannot be serialized.DataSource can be Serialized or Not:DataSet is serialized DataSource .That is why web services can always returns DataSet as the result but not the DataTables.
Example
for DataTable:
sqldataadapter
da = new SqlDataAdater("select * from Employee", con);
DataTable
dt = new DataTable();
da.Fill(dt);
datagridview1.DataSource
= dt;
Example
for DataTable:
sqldataadapter
da= new SqlDataAdater("select * from Employee", con);
DataSet
ds = new DataSet();
da.Fill(ds);
datagridview1.DataSource
= ds.table[0];
No comments:
Post a Comment