34302

C# Dataset or not? [closed]

I'm a bit confused by the Dataset concept in C# (coding ASP.NET sites, not that it matters). In my reading I'm understanding that they are used (essentially) as interfaces between my app and my data (or database). I get that. What I don't understand is some articles refer to datasets as "offline storage" where updates (inserts, etc...) are applied in batch or never, and others play more to the "interface" aspect, where reads and updates (inserts, etc...) are applied immediately to the underlining database.

Can someone please explain datasets in simple terms? Do I want to really use them? Maybe some short example cases might clear it up for me. Otherwise, I don't see why I cannot just create a simple Class that selects, inserts, updates from my database, why would I care about some XML layer?

Your wisdom is appreciated.

Answer1:

It is a tool, and it has some handy features - sometimes they are fine, but frankly I use them very very rarely personally - usually preferring simple POCOs via things like dapper (or your own preferred ORM / micro-ORM - whatever).

The main time that DataSet / DataTable is useful is if you are creating something that is itself dynamic - for example, like Stack Exchange Data Explorer - basically tools where the <strong>schema coming back</strong> is user-defined.

In most line-of-business software, this is simply not the case - so DataTable is not IMO the go-to tool.

Answer2:

A DataSet is, from one perspective, an in-memory database. The DataSet object certainly has its uses, and can be used to increase performance, make certain tasks much simpler, etc. Whether or not to use it depends on the situation. It's a tool that works well in some cases and not as well as alternatives in others.

One example of a scenario where a DataSet is a huge performance increase is in situations where you need to make multiple computations over a set of data. I/O is still a major bottleneck to performance, and it can be the case that loading a dataset into memory, and performing functions such as Sum(), Avg(), etc using DataTable.Compute is far better performance-wise than executing multiple similar statements against a true database, requiring a round-trip to the DB server on each calculation.

That's just one scenario. In a real-life application, I had to modify a program written by a previous developer, which made a connection to a Sybase SQL Anywhere function to perform multiple calculations on a sales data set.

I re-factored it to load the data once and do all computations in memory. I cannot guarantee this type of performance enhancement at all, but the program went from taking literally over 24 hours to do a batch of calculations to under five minutes.

Answer3:

You could use an ORM Tool like NHibernate or Entity Framework. With this kind of approuch you just send a object of your domain (for sample: Customer or Product) to some objects of the ORM Tool and it will save on database to you. You do not need to write a SQL command to do it, the ORM tool just do it for you easly. With an ORM you just map your domain object in a class and it will manage for you on database, like this imagem (I know it is in java, but the concept is the same for an ORM tool):

<img src="https://i.stack.imgur.com/F5LC1.jpg" alt="enter image description here">

On the other hand, you have ADO.NET internally and you can just write it, you will need to write some code, but it is not difficult.

There are a lot of reasons to does not use Dataset on .net, take a look on this article: http://www.4guysfromrolla.com/articles/050405-1.aspx

Answer4:

I would not use a DataSet. In general I deal with POCO's (Plain Old CLR Object) and use a library like Dapper to SELECT, INSERT, UPDATE, and DELETE data from the database. It's so much easier to just use a basic object that mimics my database (a domain-model if you will) and do what I need.

There are a number of examples on Dapper's site that show you how to use POCO's with Dapper.

For simple projects I just leverage ADO.NET features (e.g. ExecuteNonQuery, ExecuteScalar, ExecuteReader) off of the standard SqlCommand object. Which also doesn't need a DataSet.

Answer5:

a simple answer would be

Datasets are disconnected, thus meaning you have a table-like structure in memory.

Recommend

  • RFX equivalent data type for _int64 in Informix
  • OneToOne bidirectional mapping foreign key auto fill
  • Camel REST Bean Chaining
  • PXAction seemingly does nothing
  • disablinging autorecover option for powepoint
  • Peer to peer/adaptive payments with paypal [closed]
  • How to remove left and right margins from all wrapped rows in flexbox (without nth-child or js)
  • View Paypal shopping cart contents on my site
  • Unable to run SDL program in Eclipse but able to do so in Windows Explorer
  • Nested projects in multiproject visual studio templates
  • Ruby and class variables in inherit class
  • Insertion large number of Entities into SQL Server 2012 [duplicate]
  • How do I add a File Type Association in a Windows Phone 8.1 app manifest?
  • Retaining data after updating application
  • Where these are stored?
  • Examples of how to a STS in .Net 4.5 using WCF
  • Synchronize windows folders
  • Most efficient way to move table rows from one table to another
  • configure: error: no acceptable C compiler found in $PATH
  • Unexpected token ILLEGAL while running node.js mocha test
  • Eclipse CDT error: Unable to compile
  • How to add git credentials to the build so it would be able to be used within a shell code?
  • Problem while Building a Setup Project for a windows Service?
  • Android - Material Design - NavigationView - How to put vertical scroll?
  • Display images in Django
  • Problem deserializing objects from cache on MyBatis 3/Java
  • ActiveRecord query for a count of new users by day
  • How to delay loading a property with linq to sql external mapping?
  • Why is an OPTIONS request sent to the server?
  • Using $this when not in object context
  • How do I fake an specific browser client when using Java's Net library?
  • How reduce the height of an mschart by breaking up the y-axis
  • Is there a amazon webstore API for customers?
  • Sony Xperia Z Tablet not found by adb
  • Perl system calls when running as another user using sudo
  • VB.net deserialize, JSON Conversion from type 'Dictionary(Of String,Object)' to type '
  • embed rChart in Markdown
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app