Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Doubt between DataSet or ArrayList 1

Status
Not open for further replies.

pajarokillo

Programmer
May 3, 2004
30
ES
Hi!, i am doing a web application that will be it a Extranet.My doubt is the following, for example, you assume that i want to fill a dropdownlist with client's information, i don't know that is better and best performance, if from my logic layer to return a DataSet with the client's information or to return a ArrayList of objects of type Client and to fill the dropdownlist with the ArrayList. With the first option, my data access layer should be to return a DataSet, and with the second option it should be to return a SqlDataReader and to build a ArrayList, but i had read that the data access is more efficient to use a SqlDataReader than a DataSet. Can you help me to resolve this doubt?, thanks.
 
To give you another option, you could just use a DataTable (a DataSet is just really a collection of DataTables and it seems to me that you would only need one table?).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
>>but i had read that the data access is more efficient to use a SqlDataReader than a DataSet.

SqlDataReader can be read through just once, ie:

DropDown1.DataSource=Reader1
...
DropDown1.DataBind

'now u cant do this
DropDown2.DataSource=Reader1
...
DropDown2.DataBind

from the above example it is clear that a Reader can be used to bind data just once. once it is used in a bind command its useless.

if only one dropdown is used then i would suggest a DataReader.

if the same result has to be used through multiple controls then go in for a DataSet.

DropDown1.DataSource=DataSet1
...
DropDown1.DataBind

'Works
DropDown2.DataSource=DataSet1
...
DropDown2.DataBind

other than this DataSet has other great options too...

Known is handfull, Unknown is worldfull
 
vbkris, why would you use a DataSet (a DataTable is much more efficient if there is only one table)?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
oops, meant only a datatable.

but if my dataset has just one table then cant i use it directly???

Known is handfull, Unknown is worldfull
 
You can but it seems pointless to use a DataSet if there is only one table (it would be like creating a home network when you only use one computer!!!).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
then how else will u load data that can be traversed through? i am very new to .NET, the book i have here usually loads the SqlDataAdapter's results into a dataset, then from the dataset it derives a DataTable.

i thought i was saving time by not deriving the datatable.

i have been having a doubt regarding datasets:
- can u tell me a practical use for it.


these are the situations i came across that, but a datareader was enough:
1. Read through just one table.
2. Read through multiple tables (use a join query and return it as one).

what are the Real life uses for a dataset? why would anyone want to hold data from 2 records from a dataset when a join command can do the same?

even if caching of records is done there is a problem, the cache wont reflect the change in the data (heard this is fixed in .NET 2)...

Known is handfull, Unknown is worldfull
 
a reply i got from a friend when i quizzed him as to why he is using dataset:
"Because its got inbuilt paging functionality".


Known is handfull, Unknown is worldfull
 
then how else will u load data that can be traversed through?
A DataTable can do this.

i have been having a doubt regarding datasets:
- can u tell me a practical use for it.
A DataSet is basically a collection of DataTables (i.e it could hold multiple DataTables). You can perform relationships between these tables so think of it kind of like an in-memory database.

what are the Real life uses for a dataset? why would anyone want to hold data from 2 records from a dataset when a join command can do the same?
The tables don't have to be related. You could have a DataSet that has the results of two unrelated queries yet be able to access them through the same DataSet.

even if caching of records is done there is a problem, the cache wont reflect the change in the data
You can always store data in a session variable or in ViewState.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I typically read the data via a SqlDataReader. It is faster. It's a forward-only, read-only cursor, so it's fast.

Then, I read through the DataReader, to populate an ArrayList. Why? Because I can REUSE the ArrayList. I can use it to populate a ListItem, store some values in Session or ViewState, populate a hidden element with the previous key, all sorts of things.

I can even write the ArrayList out as cookies on the user's system to prevent a trip to the Database every page cycle.

In short, I think a SqlDataReader/ArrayList combination is the most flexible, and has good performance.

Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
great idea Tgreer.

well ca8msm i read through the article.

i have some doubts:
[qoute]
For read-only display data, Scott may have point. But for Web sites that collect information from the user and pass it back to the database, DataSets (or DataTables) are much more efficient because the data adapters have the update methods already constructed (auto generated code).
-- Dave C
[/qoute]

the update that is mentioned above will happen only after some user interaction (like updating a record). which means the following will happen:
SITUATION: Delete selected records.
-> DataSet will connect to database(using adapter) to load data (using a hidden DataReader!!!).
-> Displays data by binding to a control.
-> Reload the data once again when the page submits.
-> Detect the change in data.
-> Delete the selected records(inbuilt).
-> Rebind data.

now the DataReader point of view:
-> DataReader connects to the database.
-> Displays data by binding to a control.
-> A cusotm event is written (in javascript, event datagrid does this but it is inbuilt) that detects the id of the record that has been selected.
-> Pass data to a stored procedure.
-> Select data from database.
-> Rebind data.

agreed, in datareader the "custom coding" involed is higher. but this is just one time. from the next tim the code can be repeated or even better a control can be built easily.


it finally says that DataReader can do everything a dataset can do. and since DataReader is faster and more effecient i would prefer the DataReader. i agree that the first time it will take some time to build code for pagination etc. but with the business model that .NET comes with this is just a song.

i still have not found a situation that has required me to use a DataSet(i had one but Tgreer just solved that). i inivte comments on this statement. when i mean by real life situation i mean the normal job that a programmer would face with databases in a project.


Whew, never thought i did be this confused...


Known is handfull, Unknown is worldfull
 
i still have not found a situation that has required me to use a DataSet(i had one but Tgreer just solved that). i inivte comments on this statement. when i mean by real life situation i mean the normal job that a programmer would face with databases in a project.
How about when you have a table from one data source that has a relationship to a table in another data source? We have this situation quite frequently in my current role and DataSets have come in quite handy.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
>>How about when you have a table from one data source that has a relationship to a table in another data source

when does this happen? are ur refering to cross database relationships?

Known is handfull, Unknown is worldfull
 
Yes


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
when does that happen??? till now i havent had a chance to do that. only once i had to do cross referencing (that to to another SQL server database). that was done using T-SQL itself...

Known is handfull, Unknown is worldfull
 
We have had a few scenarios when we have had to link a SQL Server table hosted on one server to an Oracle table hosted elsewhere.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
and thats it? anyway thanks for the info...

Known is handfull, Unknown is worldfull
 
Well if you do come across a problem where you have to link two different sources, you may find that it's quite difficult and that the DataSet solves it quite nicely.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
will do. keep me updated if u find some other scenarios...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top