Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
i have 2 million record in my database which is best technique to retrieve data from databased?

SQLReader or SQlDataAdapter

What I have tried:

i have 2 million record in my database which is best technique to retrieve data from databased?

SQLReader or SQlDataAdapter
Posted
Updated 29-Jun-16 8:15am
Comments
Richard Deeming 29-Jun-16 12:44pm    
The answer is, "it depends".

Are you planning to load all 2 million records into memory at the same time? (A bad idea...)

What are you planning to do with the data once it's loaded?
Dave Kreskowiak 29-Jun-16 13:52pm    
There is no "best technique" for all queries. You use what'a appropriate for the business rules that you're dealing with at the time.

1 solution

Basically speaking, neither of them.
If you are retrieving 2,000,000 rows at once, it's going to take time. Even if each row is a single column, 10 characters wide, you would be transferring 20,000,000 bytes (without all the packaging they would need) just to fetch the data.
It's really all going to depend on what you want to do with it: a DataAdapter fetches all rows and does not return until they are all retrieved, a DataReader returns immediately, but makes a round trip to the server each time you request a new row (in fact, it doesn't, because there is a degree of buffering built in, but for that number of rows it might as well). That "spreads out" the retrieval time and can make it appear to a user that it's quicker, because the delay is amortised across each row instead of being a large dollop of time at the beginning.
But...if you are presenting this data to a user then you don't want to do that at all! There isn't a control in the world that will cope with that much data nicely, and there isn't a user in the world that wants to look at that much data in one lump!
 
Share this answer
 
Comments
phil.o 29-Jun-16 16:38pm    
"there isn't a user in the world that wants to look at that much data in one lump"
Chuck Norris does :)
OriginalGriff 29-Jun-16 17:03pm    
Chuck Norris already read it.
Twice.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900