locked
which is the best RRS feed

  • Question

  • User1499037141 posted

    which is the best for return a data from database

    SqlDataReader or DataSet or DataTable

    Friday, June 3, 2011 5:55 AM

Answers

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 3, 2011 6:20 AM
  • User1413134711 posted

    hi Sharck

    Understanding the characteristics of both the DataReader and the DataSet would give you an idea what is best for you.

    A DataSet is a container that holds data in datatables and is completely disconnected. All the fetched data would reside in memory on the client. A dataTable allows you to
    move between the rows back and forth and jum to any particular row. A dataset doesn't have any functionality for Select, Update, Delete or Insert Data. It is the job of the
    DataAdapter that provide such thing and it is a bridge that takes the communicates between the DataSet and the DataBase.

    A DataReader is similar to a firehose cursor (ReadOnly/ForwardOnly). It caches only one row at a time on the client and it is connected always with the database.

    So looks like the Dataset is your friend here. One dataset can hold all your 3 recordsets (each in one DataTable). You can move back and forth between the Datatables
    freely. Remember to bring only the needed data so that you minimize the amount of data in memory.

    If you don't care about moving between the rows back and forth and in reality you will be working on one row from each table at a time, then difinitely, the DataReader is your
    friend and it is more efficient and faster because it doesn't cache all your data in memory. Use 3 Different connection objects so that you use each with its own DataReader.

    http://www.codeproject.com/Answers/184549/Data-set-and-Data-Reader.aspx#answer3

    http://forums.asp.net/t/1281776.aspx/1?Which+is+best+datareader+or+dataset



    I hope this helps!

    if yes then please mark as answer

    thanks

    Rohit Srivastava

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 3, 2011 6:30 AM

All replies

  • User860067021 posted

    It depends of your needs.

    If you have to make the data available after retrieving it...if its only to display to user, etc etc

    Friday, June 3, 2011 6:05 AM
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 3, 2011 6:20 AM
  • User1413134711 posted

    hi Sharck

    Understanding the characteristics of both the DataReader and the DataSet would give you an idea what is best for you.

    A DataSet is a container that holds data in datatables and is completely disconnected. All the fetched data would reside in memory on the client. A dataTable allows you to
    move between the rows back and forth and jum to any particular row. A dataset doesn't have any functionality for Select, Update, Delete or Insert Data. It is the job of the
    DataAdapter that provide such thing and it is a bridge that takes the communicates between the DataSet and the DataBase.

    A DataReader is similar to a firehose cursor (ReadOnly/ForwardOnly). It caches only one row at a time on the client and it is connected always with the database.

    So looks like the Dataset is your friend here. One dataset can hold all your 3 recordsets (each in one DataTable). You can move back and forth between the Datatables
    freely. Remember to bring only the needed data so that you minimize the amount of data in memory.

    If you don't care about moving between the rows back and forth and in reality you will be working on one row from each table at a time, then difinitely, the DataReader is your
    friend and it is more efficient and faster because it doesn't cache all your data in memory. Use 3 Different connection objects so that you use each with its own DataReader.

    http://www.codeproject.com/Answers/184549/Data-set-and-Data-Reader.aspx#answer3

    http://forums.asp.net/t/1281776.aspx/1?Which+is+best+datareader+or+dataset



    I hope this helps!

    if yes then please mark as answer

    thanks

    Rohit Srivastava

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 3, 2011 6:30 AM
  • User-457099533 posted

    First compare the DataSet and DataTable:

    In Dataset you can have multiple DataTable. So depend on the data, if you have single table its either way same.

    Second comparing DataReader and DataSet/DataTable:

    DataReader is a connected, forward and read-only access to records. If you want to view record and have a connection you can use it.

    If not you can go for DataSet/DataTable

    Friday, June 3, 2011 7:40 AM