I am sure everyone but me knows about this thing by now...But man is it sweet. Thanks to
John Papa for his
ADODOTNET2 Demos.
DataTable dtNewCustomerTable;
using (SqlConnection cn = new SqlConnection(sql2005CnString))
{
/// Create the Command and Adapter
using (SqlCommand cmd = new SqlCommand(this.sqlAllCustomers, cn))
{
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
/// Create a DataTable and fill it
DataTable dtCustomers = new DataTable("Customers");
adpt.Fill(dtCustomers);
/// Create the DataTableReader (it is disconnected)
DataTableReader dtRdrCustomers = dtCustomers.CreateDataReader();
//// Loop through all of the rows and display the first col of each. Just for kicks.
//while (dtRdrCustomers.Read())
// Console.WriteLine(dtRdrCustomers.GetValue(0));
Console.WriteLine(string.Format("DataTableReader has {0} fields.", dtRdrCustomers.FieldCount));
/// Create a DataTable and load a
/// DataTable in it from the DataTableReader
dtNewCustomerTable = new DataTable();
dtNewCustomerTable.Load(dtRdrCustomers);
Console.WriteLine("Back to DataTable ... ");
/// or load a DataSet from the DataTableReader
///DataSet dsCustomers = new DataSet();
///dsCustomers.Load(tableRdrCustomers, LoadOption.OverwriteChanges, "Customers");
///Console.WriteLine(dsCustomers.Tables["Customers"];
}
}