one or more DataSets

David3410

New member
Joined
Oct 26, 2006
Messages
2
Programming Experience
Beginner
Hi!

I am David.

I request to have my doubt cleared. I begin by explaining the scenario: I am working on a VB.NET 2003 Application. It has many Forms (about 7 Forms). Each Form is based on a Table in a Microsoft Access database which is located in the "bin" folder of the Application. Any given Form, has it's controls not only bound to a main table but also has some of it's controls viz., ComboBox, CheckBox, etc., that look up for values, in other Tables, in the Database, for display.

The doubt is: Which of the following should I do:

Should I create an individual Dataset Class and Object for each Form? OR
Should I create a single Dataset Class and Object for the whole Application?
Thanks for showing considerate patience in reading the above and positively answering my doubt,

David,
Oct., 26, 2006.
 
Neither. You should create a single DataSet class and then an individual DataSet object for each form. A typed DataSet is like any other class. It's defined once in your project and then you create multiple instances wherever they're needed.
 
Hi!

Thanks, Mr. jmcilhinney.

But there is an issue. I explain it below.

I have a Form, "Movies", which has it's controls databound to the table, "tblMovies", in the Database.
I created the SelectCommand object, UpdateCommand object, DeleteCommand object and UpdateCommand object separately, manually (not through the DataAdapter wizard).
I, then, generated a DataSet object. Okay, so far.

I have another Form, "Vendor", which has it's controls databound to the table, "tblVendors", in the Database.
This form has a ComboBox, "cboMovieName", which looks-up the field, "MovieName", in the table, "tblMovies". As such, I created only one DataAdapter, "daMovies" with a single SelectCommand object (created manually via the ToolBox, ofcourse). So far, it is still okay.
I, then, generated a DataSet object. Okay, so far.

The problem is: the DataSet schema is NOW showing only two fields, viz., "ID_Movie" and "MovieName" (ofcourse, I added "ID_Movie" with the "MovieName").

IS IT OKAY, IF THE DATASET SO CHANGES?

Thanks, for going through and positively answering, in advance.

David.
Oct., 28, 2006.
 
If you create a typed DataSet then every instance will contain the full schema for every table. If you don't use them all in each instance then no problem. If you're using an untyped DataSet then there is no point adding tables and columns to it that you're not going to use. If you only need two columns of one table then that;s all you should create. Also note that there's probably no need for a DataSet at all. If all you're using in a single DataTable then the DataSet serves no purpose. Just use a single DataTable.
 
You are using .NET 2.0. You shouldnt be binding controls to DataTables directly. You should be binding them to BindingSources which in turn, bind to DataTables

A DataSet is a collection of related DataTables. If your application has no DataRelations between its DataTables then it will suffice to have a single DataSet class that you instantiate on each form. DataSet's DataTables are lazily constructed; if you never use a certain DataTable then the framework doesnt bother creating it. This means your DataSet can have 100 tables, but if your form only ever uses 1, then the other 99 will not be created and hence use (almost) no memory

There is a scenario where you will create multiple datasets when using relations. When a form is displaying related data, you may be advised to create a separate dataset for that form, if the DataSet contains a DataTable that has relations outside the scope of the form.
For example, your app has an ADDRESSES table that is used both by CUSTOMER and SUPPLIER data tables because both are entities that may have an address. ADDRESS is a child of both CUSTOMER and SUPPLIER and these references are enforced. You are creating a form to edit the customer record. Using a dataset that contains all tables and relations will fail because as you add the record for customer and then the address record, the address record will have no parent in supplier. You either disable constraints, add a dummy record to supplier or simply use two datasets, one for each form (customer editing/supplier editing) each with one relation but not the other.

You are advised to create a separate DataSet for all your tables that hold lookup values. Create one publicly accessible static instance of this DataSet, in a module, and bind all your lookup values to it. You cannot bind a Checkbox to a lookup datasource like your first post indicates, but you can bind a ComboBox viz:

myCombo.DataSource = MyModule.MyPublicStaticDataSet.SomeLookupDataTable
myCombo.DisplayMember = "Column_To_Display"
myCombo.ValueMember = "Column_With_ID_Values"

ensure that SelectedValue is bound to the datatable column that will contain the ID for this record (i.e. not the lookup table, the actual data table for the movie/person.whatever)
ensure that you remove the binding from the .Text property that is created by default.

Hope this answers all your questions!
 
Back
Top