Following Method will populate DataView from a DataReader
private DataView PopulateDataView(IDataReader
dataReader, string tableName)
{
DataTable
dataReaderTable = new DataTable(tableName);
try
{
for
(int count = 0; count < dataReader.FieldCount;
count++)
{
DataColumn
tempCol = new DataColumn(dataReader.GetName(count),
dataReader.GetFieldType(count));
dataReaderTable.Columns.Add(tempCol);
}
while
(dataReader.Read())
{
DataRow
dr = dataReaderTable.NewRow();
for
(int i = 0; i < dataReader.FieldCount; i++)
{
dr[i] =
dataReader.GetValue(dataReader.GetOrdinal(dataReader.GetName(i)));
}
dataReaderTable.Rows.Add(dr);
}
return
dataReaderTable.DefaultView;
}
catch
{
return
null;
}
}