2

I am querying a database to get a dynamically number of records, let's say I get 11000 records returned.

Currently I am inserting every record in one DataTable. I loop through each records in the table and query a web service to get more data related to this record (which I save in a Response object).

It was working fine till I didn't have more than 1000 records but apparently there's a limit on the web service that I can only query for 1000 records at a time.

I wonder how I can dynamically create 11 datatables if I have 11000 records, 12 datatables if I have 11001 records and so on. Then for each datatable I query the web service and bind the response to Response object as usual. Is this possible or is there a much better way?

Thanks in advance.

1 Answer 1

2

I haven't tested it but something like this should work.

DataTable dt = LoadDataTable()
List<DataTable> splitTables = new List<DataTable>();

for (int i = 0; i < dt.Rows.Count; i+=1000 )
{
    splitTables.Add(dt.AsEnumerable().Skip(i).Take(1000).CopyToDataTable());
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.