Given an existing DataReader
(in this case an OleDbDataReader), I can construct a DataTable
using DataTable.Load
:
// C#
OleDbDataReader dr = SomeMethodThatReturnsADataReader();
var dt = new DataTable();
dt.Load(dr);
' VB.NET
Dim dr As OleDbDataReader = SomeMethodThatReturnsADataReader();
Dim dt = New DataTable()
dt.Load(dr);
However, this loads the data from the DataReader
into the DataTable
.
I want to create a DataTable
that matches the structure of an existing DataReader
but doesn't contain any data.
How can I do this?
Edit
On further reflection, I understand there is no built-in method to do this. However, can the problem be broken down into two parts?
- Extract the schema information from the
DataReader
- Load that schema information into a new
DataTable