Datasets are what?
Datasets are a layer between the actual database and your application. When you need to connect to different tables and databases, datasets can help by separating all the connecting to your different data stores and working on the actual data. The analogy with RPG is that datasets are data structures. If you read a table in an RPG program and the put that data into a data structure, updated the fields in that data structure then moved the data structure back to your table then the dataset is the data structure and the bit that moves data between the table is the data adapter.
You don't need all this of course. It's part of .NET, specifically ADO.NET - that part of the framework that's supposed to make it easier to build complex data access application. The stuff that manages and brings it in and out of your application . Kind of like the way the RPG cycle (remember that?) reads in a table automatically. You can just read and write from any database without using datasets and adapters. It's just much easier and less error prone when you use data sets and adapters to manage your data. The IDE automatically creates these when you drop a table onto a form.
When you look at the code to fill a dataset from an adapter you can see there's not much too it. The key term here is Dataset. Datasets are completely separated from the database. Think of them as a data structure where you load data from your table to. The data structure knows nothing of the table where it got the data. It's just used to hold the data in memory. All queries, updates etc. are done to the Dataset not to the data store. We let the dataadapter take care of fetching data to and from the actual table.
// build a command object and prepare an SQL statement so that you can look at your table
SqlCommand buildData = conn.CreateCommand();
cmd.CommandText = "Select * from Orders where OrdQty >100";
// Build the Data Adapater - this fills a data set
SqlDataAdapter dataAdapter = new SqlDataAdapter(buildData);
// Now create the data set. The data structure which contains the data retrieved by the data adapter
DataSet orderDataSet = new DataSet();
// Populate the dataset with the Data Adapter
dataAdapter.Fill(dataSet);
2 Comments:
Can you tell me where I can download the OLEDB driver?
This is great. There is so much extraneous detail to C# that can make the learning of it confusing. I'm an RPGIV developer with 20 years experience and sometimes this language makes me feel plain dumb! Thanks for making it clear and simple!
Post a Comment
Subscribe to Post Comments [Atom]
<< Home