问题
I am loading a large result set of about 3 million rows (ADODB record set) into a data table. Its taking too long to even load the result set into a data table. I want to find out a way of extracting only part of a result set and then loading it into a DataTable. Alternatively, is there a way to directly read the recordset directly instead of loading it into a data table and then reading it ?
This is the code I use to fill my DataTable -
OleDbDataAdapter oleDA = new OleDbDataAdapter();
DataTable dt = new DataTable();
oleDA.Fill(dt, myADODBRecordset);
回答1:
Here are some options to consider:
Get only the rows and columns you really need to work with.
Get some data and let the user ask for the next set of rows when they want to.
Write optimized SQL queries
Don't use a DataTable unless you have to because it contains more metadata information that other list-type objects.
Consider using a managed .NET provider.
回答2:
Why load so large data into memory? A large data transaction must comsume large resource, so optimize your code, or use EF.
来源:https://stackoverflow.com/questions/19918848/handling-a-large-adodb-record-set-in-data-table