Results 1 to 7 of 7

Thread: Master Detail relations using new and old methods

  1. #1

    Thread Starter
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Master Detail relations using new and old methods

    Do not want to read all the following? Then go right to the download and test drive the project. There is nothing truly new here but then again there might be something that gets you thinking in a different direction.

    Requires VS2008 or higher using Framework 3.5 or higher

    The purpose of this code bank post is to provoke thoughts in regards to utilizing language method extensions using as an example creating a master/detail which most examples found on the web are very simple (which is not bad) yet do not explain how to work your data manually.

    Many developers will add a data source to a project, drop various data components onto forms and go about developing their solution. This works fine yet there are times with complex application this does not work. Also there are solutions this is not possible, for example, IBM data provider is not up to par with MS-SQL server in regards to helper components or do not have support say for Data Context.

    With this in mind the attached project show a more manual approach to setting up a master/detail relationship between two tables. Also there is several language extension methods included which do not add anything other than removing the complexities of operations into wrappers. These wrappers for some will make it easier to get results rather than attempting to remember “how do I do that?”

    What can make a difference when enclosing (at least for me) logic into wrappers which can be functions, procedures or functions and procedures into extension methods is the Intellisense description text. With that said if these methods work for you make sure the descriptions which appear when using them makes sense. Also if the method name does not make sense to you then by all means change the name.

    To being, compile the project then run it. You will see two DataGridView controls, top for master and bottom for detail rows. As you scroll through the master DataGridView note that the default child row is displayed to the editor’s output window. This demonstrates getting back information about the current detail row using a language extension method which is not pretty so we make it pretty by using an extension. As you scroll through the Details DataGridView the same logic is used for scrolling in the master DataGridView, show the current row items.

    Speaking of making things pretty, there are two DataGridView language extension methods. The first is project specific which hides the ID columns in both DataGridView controls. The second uses the underlying DataTable column captions for their DataGridView column header text.

    Caveat: If you want to place break points in the code you will need to comment out the following attribute for any function or procedure you are going to trace into

    Code:
    <System.Diagnostics.DebuggerStepThrough()> _
    Attached Files Attached Files

  2. #2

    Thread Starter
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Re: Master Detail relations using new and old methods

    This version shows how you can search for a value in a child column using the Find method of a BindingSource where the value exists in the underlying DataTable but not for the current master child rows.
    Attached Files Attached Files

  3. #3
    Hyperactive Member
    Join Date
    Nov 2013
    Posts
    292

    Re: Master Detail relations using new and old methods

    This was very helpful.

    I have a similar scenario and could use some assistance / advice / examples to look at.

    My database is MSAccess 2003. My VB is Community 2013.

    I have a form that I'm feeding data to from 3 database tables. Two sections of the form are getting data in textboxes from 2 of the tables and there's also a datagridview receiving data from a 3rd table.

    The form's binding navigator is working just fine for one section populated by text boxes from tableA. What is not happening is the other two sections do not advance their records when the binding navigator advances. That's what I'm trying to get corrected.

    I looking at the code example provided by "KevinInstructor" I get the overall picture of how it should work.

    Question 1 - How do the relationships established in Access tie in to the relationships in VB? I see the VB relationships can be edited in the designer. I'm not sure which setting to change them to though.

    Question 2 - I found that when I go back into Access and alter the relationships, VB then creates another binding source in the designer. This has caused me some confusion and frustration. Will altering the relationships in the dataset designer have a similar effect?

    Question 3 - Between Access relationships and VB Dataset Relationships..... which one overrides the other?

  4. #4

    Thread Starter
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Re: Master Detail relations using new and old methods

    In short, if you run "custom tool" by right clicking in the dbml file in Solution Explorer changes made in MS-Access should be seen and code written for you for said changes. In regards to the last question, unless when making changes to the physical database you don't run custom tool Visual Studio will not know of the changes so to feed the changes to Visual Studio you must run custom tool.

  5. #5
    Hyperactive Member
    Join Date
    Nov 2013
    Posts
    292

    Re: Master Detail relations using new and old methods

    Quote Originally Posted by kevininstructor View Post
    In short, if you run "custom tool" by right clicking in the dbml file in Solution Explorer changes made in MS-Access should be seen and code written for you for said changes. In regards to the last question, unless when making changes to the physical database you don't run custom tool Visual Studio will not know of the changes so to feed the changes to Visual Studio you must run custom tool.

    Thank you for replying. I don't see a dbml file in my solution explorer. I'm researching what they are for and from what I've read so far...it sounds like something that if I do find it...I could get things all fouled up tinkering with it..

  6. #6

    Thread Starter
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Re: Master Detail relations using new and old methods

    Quote Originally Posted by larrycav View Post
    Thank you for replying. I don't see a dbml file in my solution explorer. I'm researching what they are for and from what I've read so far...it sounds like something that if I do find it...I could get things all fouled up tinkering with it..
    Then look for the xsd file with the database name in Solution Explorer. My bad, the other file is for Entity Framework.

  7. #7
    Hyperactive Member
    Join Date
    Nov 2013
    Posts
    292

    Re: Master Detail relations using new and old methods

    Quote Originally Posted by kevininstructor View Post
    Then look for the xsd file with the database name in Solution Explorer. My bad, the other file is for Entity Framework.

    Thanks again... I found that. It's set to MsDataSetGenerator. I learned something from this that might be helpful down the road...

Tags for this Thread

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