You can load a DataTable
directly from a data reader using the Load()
method that accepts an IDataReader
.
var dataReader = cmd.ExecuteReader();
var dataTable = new DataTable();
dataTable.Load(dataReader);
More Related Contents:
- ExecuteReader requires an open and available Connection. The connection’s current state is Connecting
- MetadataException: Unable to load the specified metadata resource
- Get output parameter value in ADO.NET
- When should “SqlDbType” and “size” be used when adding SqlCommand Parameters?
- SQLite Database Locked exception
- Is it necessary to manually close and dispose of SqlDataReader?
- When using Trusted_Connection=true and SQL Server authentication, will this affect performance?
- Difference with Parameters.Add and Parameters.AddWithValue
- SqlConnection SqlCommand SqlDataReader IDisposable
- Exception when AddWithValue parameter is NULL
- Calling Oracle stored procedure from C#?
- Insert into C# with SQLCommand
- MultipleActiveResultSets=True or multiple connections?
- How to pass a table-value parameter
- How DataReader works?
- How to keep single SQL Server connection instance open for multiple request in C#?
- DataTable equivalent in Java [duplicate]
- How do I re-write a SQL query as a parameterized query?
- Check if a SQL table exists
- What is the difference between dataview and datatable?
- Reading a date using DataReader
- What ‘length’ parameter should I pass to SqlDataReader.GetBytes()
- How do I connect to a SQL database from C#?
- .net connection pooling
- Do we have transactions in MS-Access?
- Sorting Win Form CheckListbox [closed]
- Best way to store encryption keys in .NET C#
- Is there a possibility to differ virtual printer from physical one?
- Parsing a Auto-Generated .NET Date Object with Javascript/JQuery
- Which C# method overload is chosen?