Question creating DataSet in different forms

kfirba

Well-known member
Joined
Dec 29, 2012
Messages
77
Programming Experience
1-3
Hello!

Let's say I got a dataset named TestDataSet and I want to use this DataSet in another 3 forms. When I drag a GridView on other form than the main, it automatically creates BindingSource, DataSet TableAdaper and etc.

If I update the new DataSet that has been created by the wizard when I dragged the GridView , will it update the Dataset that I have on the main form?

for example:

MainForm has a DataSet named TestDataSet.
SubForm has a DataSet named TestDataSet1.

Whenever I add a record, delete a record and etc. at TestDataSet1 or TestDataSet will it update the information to the other DataSet? If not, is there any way to do it? Because working with the wizard, saves LOT time and it's much easier than typing the code. By dragging a GridView, the wizard does everything for me! creates a BindingSource, DataSet, BindingNavigator, Adapters and sets their attributes, that's really helpful! especially when you are dragging a GridView that has a relationship with another table, that automatically uses a query without me doing anything.

I hope it's possible!

Thanks in advance!
 
If you add a TextBox to MainForm and a TextBox to SubForm, would you expect a change in one TextBox to affect the other? I would think not, so there's no reason to think that DataSets should be any different. Two different objects are two different objects. Just as in the real world, changes to one instance of a thing of a particular type do not inherently affect any other instance of a thing of the same type. If you want to use the same object then you have to use the same object. Each object can only be created in one place, so you'd have to pass it from that place to the other.

Do you really need the same DataSet object anyway? What exactly is the relationship between these forms and the data they display? It may be that three separate DataSets is appropriate. If not then it's not much effort to add the bit of code required.
 
If you add a TextBox to MainForm and a TextBox to SubForm, would you expect a change in one TextBox to affect the other? I would think not, so there's no reason to think that DataSets should be any different. Two different objects are two different objects. Just as in the real world, changes to one instance of a thing of a particular type do not inherently affect any other instance of a thing of the same type. If you want to use the same object then you have to use the same object. Each object can only be created in one place, so you'd have to pass it from that place to the other.

Do you really need the same DataSet object anyway? What exactly is the relationship between these forms and the data they display? It may be that three separate DataSets is appropriate. If not then it's not much effort to add the bit of code required.

lets say I have a pets table,appointments table, owners table and etc.

i want to display in one form all of the pets and their appointments. I want to display the pets as Detail and the appointments as DataGridView. I couldn't find a way to do it without filling the DataGridView with a query, and even then, if I select in my query to not show some row, the DataGridView still shows that row but empty. In order to get around the code and the problem, I can just do what I want by simply dragging 2 objectives on my form.

Anyways, when it is appropriate to work with 2 DataSets in one project?

Thanks in advance!
 
It's important to understand how you're using the word "DataSet". Just like forms, you can design one form in your project and then display multiple instances of it in your application. When you generate a DataSet in your project you are creating a class. There is just one DataSet class per database. When you run your application, you might create many instances of that class.

In your case, you should just stuck with your original idea. You just need one form with one DataSet instance and you can bind the data in a master/detail configuration. Here's an explanation of how to perform that binding:

Master/Detail (Parent/Child) Data-binding

In your case, the parent BindingSource gets bound to your TextBoxes, etc, and your child BindingSource to the grid.
 
It's important to understand how you're using the word "DataSet". Just like forms, you can design one form in your project and then display multiple instances of it in your application. When you generate a DataSet in your project you are creating a class. There is just one DataSet class per database. When you run your application, you might create many instances of that class.

In your case, you should just stuck with your original idea. You just need one form with one DataSet instance and you can bind the data in a master/detail configuration. Here's an explanation of how to perform that binding:

Master/Detail (Parent/Child) Data-binding

In your case, the parent BindingSource gets bound to your TextBoxes, etc, and your child BindingSource to the grid.

I see. What if I create 2 instances of the DataSet and whenever I'm making a change on one of them, I update the DataBase and then update the other DataSet? With that way, I can have 2 DataSets with the same information all the time. Is it acceptable?
 
Is it acceptable?
No, not especially. If you want one set of data maintained at a particular time then you would use one DataSet. If you don;t need the one set of data maintained then you would use multiple DataSets as required. For instance, if you have one form open to edit data in one table and then you open another form to edit data in another table, the data does not overlap so you would separate DataSets. If two forms are working on the same data though, you would pass the DataSet, or some part thereof, from the first form to the second. Don't try to make this difficult when it is not a special situation. All objects should be treated the same way.
 
No, not especially. If you want one set of data maintained at a particular time then you would use one DataSet. If you don;t need the one set of data maintained then you would use multiple DataSets as required. For instance, if you have one form open to edit data in one table and then you open another form to edit data in another table, the data does not overlap so you would separate DataSets. If two forms are working on the same data though, you would pass the DataSet, or some part thereof, from the first form to the second. Don't try to make this difficult when it is not a special situation. All objects should be treated the same way.

How do I know when I have to import to my DaaSet all of the ttables from the Database and when only part of it? Why won't I just import all and pass the DataSet from a form to another?
 
The DataSet contains all the DataTables regardless. It's a matter of which of those tables you populate with what data. Presumably you know what data each form needs so you only retrieve that data. If your database, and therefore DataSet, contains 10 tables and a particular form only works with data from one of them then that's the only DataTable you populate.
 
The DataSet contains all the DataTables regardless. It's a matter of which of those tables you populate with what data. Presumably you know what data each form needs so you only retrieve that data. If your database, and therefore DataSet, contains 10 tables and a particular form only works with data from one of them then that's the only DataTable you populate.

I'm not sure I fully understood what you meant. If possible an example would help me a lot
 
Back
Top