Click here to Skip to main content
13,504,202 members
Rate this:
Please Sign up or sign in to vote.
See more: , +
I want to ask on how I can create a master detail table form with vb net sqldataadapter, is there a way I can do it with the components properties? or do I have to write an sql command with sql's join statment?

Thank you
Posted 7-Feb-13 19:23pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Without knowing what you're going to do with that data, liek what control you're going to use to display this, and if you want the detail records for every row to be displayed without selecting a master row, we're just guessing.

But, if you're planning on using the DataGridView to try and achieve this, you'll be disappointed. Showing details in a subtable in a DGV isn't supported.

But, if you're only showing master records and then showing the detail records for a single selected master, you only need to retrieve the master records and show them, then when one of those is selected by the user, you can make a second query to get the details and show them in another control(s) somewhere.

If you're showing something of a report on your form with all the master and detail records displayed at the same time, then you'll have to write your query differently to return the two tables in a related set.
Member 3892343 8-Feb-13 15:42pm
Hello Dave,
I have configured 2 sqldataadapters 1 for master 1 for detail, I have generated 1 dataset from both (right click generate dataset), I dbl click the dataset and in the designer I cinnected the 2 tables of the adapters, in a relationship (drag the mouse from PK tb1 to FK tb2) I have textboxes for the 2 tables and a picturebox for the details (it has a blob field and 2 other fields). I have put buttons to navigate for both master and detail smthng like me.bindingcontex.dataset.position= me.bindingcontex.dataset.position + 1. When I press the next button for the master it changes the detail as well but when I press the button for the detail it goes through all the detail table not just the current master's detail records, I want to know if it is normal since I have created the relationship in the dataset. How I solved it? I insert a query in the detail adapter which has a parameter like search and through a textbox (which has the PK of the master) I give to the parameter the value for the FK of the detail, it works but I was wondering if it can be done without the query or am I doing smthing wrong with the first approach?
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

First, I avoid using the Designers at all costs and prefer to write all my database handling code myself. That way, I know EXACTLY what every piece of code is doing and there's no code hiding somewhere in the Designer generated files doing things without me knowing about it.

What do the queries look like for the master and detail? What does the code look like for populating the tables in the dataset? You ARE using a single dataset object, correct? What does the code look like for adding the relation between the tables? How about the code to bind the controls to data?

You should be setting the DataSource for the MasterBindingSource to the DataSet object and the DataMember property set to the name of the master table in your DataSet. Then you set the DetailsBindingSource.DataSource to the MasterBindingSource and set the DataMember property to the name of the details table in your DataSet.
Member 3892343 9-Feb-13 13:11pm
Thank you Dave it worked, but as to code I think it is very time consuming, I can code the components and I will try it to next project.

Thanks again

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.180417.1 | Last Updated 8 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100