What is a Dataset and what is its function?

Asked

Viewed 5,112 times

2

Creating my first database applications (SQL Server), I connect by passing my string and using the Sqlcommand class to pass the query.

But searching other sites, I see that access to the bank is done via Dataset.

What would be a Dataset and what its function?

  • 1

    google will return you several tutorials on the subject, here in OS you can ask a more specific question about code, for example "How to fill the Dataset through a precedent?" , assuming you’ve tried some things and can show your code and where you’re doubtful. Just to clarify, Dataset is not used for access to the database, it stores data

2 answers

8


First you must understand what ADO.NET. It is an access layer between some data store (not limited to the database) and your .NET. application.In your case, to access the SQL Server information there is the ADO.NET layer that will intermediate between your database and your application. The Sqlcommand you mentioned is a ADO.NET architecture class that helps in this process.

The Dataset does not serve to access the database. Dataset abstracts this data external to the framework when in memory, being it independent of the data source. For example, when you make a request to the database:

SELECT * FROM PESSOAS WHERE PESSOAS.NAME LIKE 'COLETTA'

The database will process this SQL, and when it reaches the data access layer, it will store this information in memory, as an example in a Dataset or Datareader, according to the implementation.

With the Dataset structure, I can manipulate my data in memory with its Datatable and Datarelation, equal to the relational structure of the databases. Example:

//criando o dataSet;
DataSet exemplo = new DataSet("EXEMPLO");  
DataTable peopleTable = exemplo.Tables.Add("PESSOAS");
peopleTable.Columns.Add("Name", typeof(string));

Note in this example that I created a table called PEOPLE with a column called Name. Now I can add records within this structure:

DataRow myRow = exemplo.Tables["PESSOAS"].NewRow();
myRow["Name"] = "COLETTA";

My example is really simple and wouldn’t be much use, but the idea is to exemplify how the structure is created. By creating these structures, you could insert into your Sql Server database using the SqlDataAdapter.Update(exemplo);

4

The dataset, as the name says, it is just a set of data. It is finite and has a specific function and feature.

We use it to process data that came from the database through some query, often through an SQL command, then comes the columns and rows of the tables that you determine. All that matters to what you’re gonna do in that operation is dataset assembled by the consultation made.

A dataset can be mounted manually or via a framework, like the Entity Framework that is often used with . NET.

ADO.NET have its own DataSet. He’s considered more or less obsolete. Not that it can not be used and not useful, but in most cases if using it strongly becomes too heavy it pays to use the EF.

When you need to do something simpler it’s usually more interesting to have just one DataReader (specific to SQL Server) and then engrave in the hand what it needs, in a form called disconnected, perhaps through a DataAdapter.

So it’s an abstraction to access data that came from a data source, probably a database, which could be SQL Server, so it indirectly accesses the database data through a "mirror" in memory.

I would avoid its use unless it makes a lot of sense. Some people like it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.