More on DataTable in ADO.Net 2.0

The DataTable's CreateDataReader method creates an instance of DataTable Reader. When a DataTableReader is created from a DataSet or a DataTable's CreateDataReader method, the DataTableReader will contain all of the rows from the container object, with the exception of deleted rows.
The DataTableReader is a lighter weight object than the DataTable and, unlike the DataReader (SqlDataReader), the DataTableReader is disconnected. This is a great feature because you get the lightweight object that you can iterate through quickly (like the DataReader) and it is disconnected from any data source (unlike the DataReader). A DataTableReader can be thought of as an iterator over the underlying table's rows, similar to a foreach enumeration of the contents of the table.Keep in mind that the DataTableReader only moves forward.
The following example shows how you can create a DataTableReader.
using (SqlConnection cn = new SqlConnection(cnStr))
SqlCommand cmd = new SqlCommand(sqlAllCustomers, cn);
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
DataTable dtCustomers = new DataTable("Customers");
DataTableReader dtRdr = ds.CreateDataReader();
dgvCustomers.DataSource = dtRdr;

Loading multiple Table's in DataTableReader is similar to the retriving multiple resultset. the method NextResult can be used to move to other table's records.
DataTableReader dtRdr = dt1.CreateDataReader();
DataTable dt2 = new DataTable();

Like Dataset Merge, Two Tables can be merged together by the method Merge of DataTable.

Similar to DataSet, DataTable can be written as XML by the WriteXml method. the DataTable in ADO.NET 2.0 also exposes the ReadXml, ReadXmlSchema, and WriteXmlSchema methods.
The DataSet also has some new methods and properties. In fact, both the DataSet and the DataTable now expose the RemotingFormat property as well as the Load and CreateDataReader methods. The RemotingFormat property is used to indicate whether to serialize the DataTable or DataSet in binary or XML format.

No comments:

Post a Comment