Let see where to start. When .Net was introduced it wreaked
havoc on a lot of developers and especially people that where caught still in
the VB6 learning curve. I know anyone who already has dealt with dataset
objects will now these things. But for the beginner here goes.
A dataset is merely a “in memory” copy of the data you specify
using your data adapter. Let me elaborate.
First you will need a connection
Dim conntrans as new oledbconnection
Or you could drag it from the “data” toolbox and the
interface will come up asking you to which data source you want to connect. For
a single tier program this is the way to go.
After you get your connection set up and tested, you will
need a data adapter, which is basically a query on your database, the data
adapter wizard will help you set this up and then you can take a peek in the
#windows form generated region to see what code is involved in this.
Now for your dataset, the easiest way to get your dataset is
to right click your adapter object and click generate dataset. After specifying
a name for your dataset you will see that it adds a schema xml file with that
name and that your dataset has that name with a “1” appended to it.
In the form load event of the form containing your dataset,
you must fill it, Yeah kinda looks like it would auto
fill when called , but I guess not. To do this you call
Dataadaptername.fill(datasetname)
Replacing the dataset name and data adaptername with your names.
Now here is the good part, any changes you make or records
you add or not uploaded to the database until you call the acceptchanges() procedure,
this is because it is still a disconnected dataset. There are gobs of methods
& properties (merge, haschanges, etc etc) that can be called but for the most
part they are accepting changes, rejecting changes or updating the disconnected
data.
You are now able to bind objects to that dataset; textboxes,
combo boxes, etc. also note that a combo box can easily be bound to two
datasets. One for the items in it by setting the data source and then the
display member & value member, and the selectedItems
property in the data bindings can be set to yet another dataset.
I am in the middle of
programming a 4-tier application that has a Win32, Intranet & internet
interfaces and once done I will post a whole entire tutorial on data access
layers and their functions relating to re-usable code. I just felt the need to
answer this so that people would know what a dataset is.
|