tags:

views:

164

answers:

5

I have been developing many application and have been into confusion about using dataset. Till date i dont use dataset and works into my application directly from my database using queries and procedures that runs on Database Engine.

But I would like to know, what is the good practice Using Dataset ? or Working direclty on Database.

Plz try to give me certain cases also when to use dataset along with operation (Insert/Update)

can we set read/write lock on dataset with respect to our database

+4  A: 

You should either embrace stored procedures, or make your database dumb. That means that you have no logic whatsoever in your db, only CRUD operations. If you go with the dumb database model, Datasets are bad. You are better off working with real objects so you can add business logic to them. This approach is more complicated than just operating directly on your database with stored procs, but you can manage complexity better as your system grows. If you have large system with lots of little rules, stored procedures become very difficult to manage.

Michael Valenty
DataSets are the black eye of the .Net framework. Avoid at all costs.
Chuck Conway
+1  A: 

As a rule of thumb, I would put logic that refers to data consistency, integrity etc. as close to that data as possible - i.e. in the database. Also, if I am having to fetch my data in a way that is interdependent (i.e. fetch from tables A, B and C where the relationship between A, B and C's contribution is known at request time), then it makes sense to save on callout overhead and do it one go, via a database object such as a function, procedure (as already pointed out by OMGPonies). For logic that is a level or two removed, it makes sense to have it where dealing with it "procedurally" is a bit more intuitive, such as in a dataset. Having said all that, rules of thumb are sometimes what their acronym infers...ROT!

In past .Net projects I've often done data imports/transformations (e.g. for bank transaction data files) in the database (one callout, all logic is encapsulated in in procedure and is transaction protected), but have "parsed" items from that same data in a second stage, in my .net code using datatables and the like (although these days I would most likely skip the dataset stage and work on them from a higher lever of abstraction, using class objects).

davek
+2  A: 

In ye olde times before MVC was a mere twinkle in Haack's eye, it was jolly handy to have DataSet handle sorting, multiple relations and caching and whatnot.

Us real developers didn't care about such trivia as locks on the database. No, we had conflict resolution strategies that generally just stamped all over the most recent edits. User friendliness? < Pshaw >.

But in these days of decent generic collections, a plethora of ORMs and an awareness of separation of concerns they really don't have much place any more. It would be fair to say that whenever I've seen a DataSet recently I've replaced it. And not missed it.

Jeremy McGee
A: 

I have seen datasets used in one application very well, but that is in 7 years development on quite a few different applications (at least double figures).

There are so many best practices around these days that point twords developing with Objects rather than datasets for enterprise development. Objects along with an ORM like NHibernate or Entity Framework can be very powerfull and take a lot of the grunt work out of creating CRUD stored procedures. This is the way I favour developing applications as I can seperate business logic nicely this way in a domain layer.

That is not to say that datasets don't have their place, I am sure in certain circumstances they may be a better fit than Objects but for me I would need to be very sure of this before going with them.

Burt
A: 

I have also been wondering this when I never needed DataSets in my source code for months.

Actually, if your objects are O/R-mapped, and use serialization and generics, you would never need DataSets.

But DataSet has a great use in generating reports.

This is because, reports have no specific structure that can be or should be O/R-mapped.

I only use DataSets in tandem with reporting tools.

JMSA
i have been using datatables instead of dataset for reporting. By creating a view at the database i direclty use data table linked with a view for reporting.
Shantanu Gupta