One project, one Database but multiple forms.
I have a fairly simple question (I guess): If I have one project that connects to only one database(Access) with one table, but in my project I have 3 forms. One for displaying and filtering data(datagridview). One for editing(detail view with textboxes) and one for adding data(detail view with textboxes).
How should I set up dataadapters and datasets(should I use existing dataset or create new). Do I have to set them up on every form independently or what? What is the best practice for this kind of situation?
Re: One project, one Database but multiple forms.
Are you adding tables etc. at design time or dynamically?
Re: One project, one Database but multiple forms.
Quote:
Originally Posted by
dunfiddlin
Are you adding tables etc. at design time or dynamically?
What is the difference between them?
Let's say I want to add tables etc. at design time...
Sorry, I am still learning the secrets of databases and vb.
Re: One project, one Database but multiple forms.
Re: One project, one Database but multiple forms.
You should only have one dataset, if you are going to have a dataset for this (you don't HAVE to, but you probably do need to). If you don't do it that way, then each form would have to open the connection, get the data into their own dataset, then close the connection. You might then make changes on form A, but form B wouldn't know about those changes, because it has a different view of the data, so once form A was done, form B would have to go back to the database and refresh its information.
A better design would be to have one dataset that all forms share. Any changes made by form A would be instantly seen by form B, because they would be sharing the dataset. You could then make as many changes as you wanted to, by whichever form you felt should make the changes, and only when you are ready would you push those changes back to the database.
Re: One project, one Database but multiple forms.
Quote:
Originally Posted by
dunfiddlin
Ok, I misunderstood you. Design time = with wizard and dynamically=programmatically. Yes, I have studied these tutorials already.
Unfortunately these tutorials didn't answer my question that I brought up in post 1.
Re: One project, one Database but multiple forms.
Quote:
Originally Posted by
lkallas
I have a fairly simple question (I guess): If I have one project that connects to only one database(Access) with one table, but in my project I have 3 forms. One for displaying and filtering data(datagridview). One for editing(detail view with textboxes) and one for adding data(detail view with textboxes).
How should I set up dataadapters and datasets(should I use existing dataset or create new). Do I have to set them up on every form independently or what? What is the best practice for this kind of situation?
Kind of up to you. You could do it inline whenever you needed to access the database. You could make a class you reference from all of them. You could make a class you instantiate an instance of in all of them. Really up to you. Not sure there is really a right or a wrong way.
Re: One project, one Database but multiple forms.
Design time data objects can be accessed like this ... Form1.SomeBindingSource
If you're creating a Dataset dynamically then declare it thus ... Public DBSet As DataSet ... and all tables associated with the dataset are available from all forms. DataAdapters, however should always be declared separately in every Sub in which they are used.