Hello, i want to fill a Datatable with a Datareader row by row but get an exception because the reader's columns have a different order than the Datatable's columns.
Why and how does a Datatable loads itself with a Datareader correctly, even so it has a column collection with different order?
I need to calculate values for every row so i dont want to load the Datatable completely but row for row. It has 25 columns so i dont want to set it all manually.
There must be a chance to load/fill/add a new row from a datareader without having the same column order(reader.GetSchemaTable?). Thanks
Following is what i have but what doesnt work:
Using reader As System.Data.SqlClient.SqlDataReader = command.ExecuteReader
'next line works(configInfo.DataSource is a Datatable)but is inappropriate
configInfo.DataSource.Load(reader)
While reader.Read
Dim allCols(reader.FieldCount - 1) As Object
reader.GetValues(allCols)
'following both methods are throwing exception because of the wrong column order
configInfo.DataSource.Rows.Add(allCols)
configInfo.DataSource.LoadDataRow(allCols, True)
'now i want to do some calculations on this row ....
End While
End Using