Results 1 to 8 of 8

Thread: One project, one Database but multiple forms.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2012
    Posts
    75

    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?

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: One project, one Database but multiple forms.

    Are you adding tables etc. at design time or dynamically?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2012
    Posts
    75

    Re: One project, one Database but multiple forms.

    Quote Originally Posted by dunfiddlin View Post
    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.

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: One project, one Database but multiple forms.

    What's the difference? Is it like this http://www.homeandlearn.co.uk/net/nets12p2ed.html or like this http://www.homeandlearn.co.uk/net/nets12p4.html or have you not even got that far yet?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    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.
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Aug 2012
    Posts
    75

    Re: One project, one Database but multiple forms.

    Quote Originally Posted by dunfiddlin View Post
    What's the difference? Is it like this http://www.homeandlearn.co.uk/net/nets12p2ed.html or like this http://www.homeandlearn.co.uk/net/nets12p4.html or have you not even got that far yet?
    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.

  7. #7
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Re: One project, one Database but multiple forms.

    Quote Originally Posted by lkallas View Post
    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.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  8. #8
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width