简体   繁体   中英

Using SqlDataAdapter or SqlDataReader, which one is more efficient and puts minimum load on server?

I am writing an ASP.net C# program, in which I have to do multiple trips to SQL database and for retriving small small data many times. Please suggest which way is more efficent? Should i use SqlDataAdapter and store entire data in DataTable and retrieve when needed or used SQLDataReader instead, Please suggest any other efficient way if any. thanks!! :)

Neither sounds very good. Getting all of the data and cherry-picking what you need sounds inefficient on both sides (server and clients) while sending lots of tiny sql requests sounds inefficient as well.

Ideally you would get all of the data that you need (but no more) in as few requests as you can. Choosing between SqlDataAdapter and SQlDataReader doesn't solve that for you. You need to look at your design and determine if you can get all of the related data for a page without keeping an in-memory copy of your entire database.

BTW, SqlDataAdapter uses a SqlDataReader internally to get its data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM