Write for Us
The Load method of the DataTable class of ADO.NET 2.0 can be used to load a DataReader instance directly into a DataTable instance. The following listing shows how it can be accomplished. SqlConnection sqlConnection = new SqlConnection(sqlConnectionString);sqlConnection.Open();SqlCommand command = new SqlCommand(“Select name, population, area from States”, sqlConnection);SqlDataReader sqlDataReader = command.ExecuteReader();DataTable dataTable = new DataTable ();dataTable.Load(sqlDataReader, LoadOption.OverwriteChanges);
string connectionString = ...; //Some connection string DataTable dataTable = new DataTable("Employee");SqlConnection sqlConnection = new SqlConnection(connectionString)) SqlCommand sqlCommand = sqlConnection.CreateCommand(); sqlCommand.CommandText = "SELECT empCode, empName from employee"; sqlConnection.Open(); dataTable.Load(sqlCommand.ExecuteReader(CommandBehavior.CloseConnection)); DataTable cloneTable = dataTable.Copy();
New Features in ADO.NET 2.0
What's New in ADO.NET (MSDN)
DataView Sorting Filtering and DataBinding in ADO.NET 2.0 - Converting DataView to Table - ADO.NET Tutorials
DataSet and DataTable in ADO.NET 2.0 (MSDN)