Page 1 of 2

Tutorial on many-to-many relations DB in VB.net

Posted: Wed Jun 15, 2011 10:12 pm
by NewGuy
Hey there....

ok .. i give up :) well.. not quite, but i am trying to wrap my head around using databases in VB.net .. and i know how to instansiate a DB .. make it a part of the project... i know how to make tables.... i even know how to make relations between tables .. BUT .... i cant figure out "many-to-many" relations and how to dislay this on forms

i know that you need 3 tables for this .. and you need the two original tables, and they need have a primary key .. and the joining table (in the middle, in terms of relations) has to have its own primary key AND the foreign key of the other two tables.. so fare soo good

I am trying to make a training program simular to the illustrations i made for this question (this is not a actual database i have yet.... illustrations is just made in photoshop) :)

.... so i got the database schematics pinned down i think ..

But i cant figure out how to make VB.net do this :

1. on the "individual training log" form show all training sessions the person has ever attended (ex. John) .. including the specific equipment he used for each individual training session

2. on the "training session" form show all available persons from "individual training log" in ex. a listbox

3. and when their name is dragged onto the picked training equipment for the day .. save that information into the gridview below .. which then again will be reflected back to the"individual training log" form - so that the individual person can see which equipment he used at each training session

so basically what im asking for, is a tutorial on, "many to many relational DB'ing in vb.net ... including the tricky part ... pulling information from the different database tables (see attachment) .. and displaying it on forms"

it is NOT important to include all the "person details" for each individual in the tutorial .. the important stuff is to show how to make the relations work .. and display of data related to these relations

if anyone would find it interessting to make such a tutorial .. i am eternally greatfull .. and im sure im not the only one struggling with "many to many " relations :-)

Thank you for the time you spend reading this

Im new at this .. but i find it soo interresting that sometimes i even dream in code :D

New Guy :-)

Re: Tutorial on many-to-many relations DB in VB.net

Posted: Thu Jun 16, 2011 6:05 am
by MrAksel
Ask Dummy, he knows alot about databases
Edit: Yes, I meant Dummy1912

Re: Tutorial on many-to-many relations DB in VB.net

Posted: Thu Jun 16, 2011 6:42 am
by NewGuy
MrAksel wrote:
Ask Dummy, he knows alot about databases

Hi MrAksel

did you mean "Dummy1912" ? :)

Re: Tutorial on many-to-many relations DB in VB.net

Posted: Thu Jun 16, 2011 8:48 am
by Dummy1912
omg;

Does anybody call my name? hehaho;

Hi Newguy,
Whats wrong...
did you download my tutorials about databases?
maybe that can help you out a little.

Dummy1912

Re: Tutorial on many-to-many relations DB in VB.net

Posted: Thu Jun 16, 2011 11:59 am
by NewGuy
Dummy1912 wrote:
omg;

Does anybody call my name? hehaho;

Hi Newguy,
Whats wrong...
did you download my tutorials about databases?
maybe that can help you out a little.

Dummy1912
Hi Dummy1912 .. thanks for answering me

i dont use Access databases .. but i make the database through VB.net ... and want to learn to use the the "table adapter" - "Binding source" and dataset tools which VB.net provides .... and at the same time im trying to figure out how to do the 3 things i listed above .. can you help ? .. maybe even make s small example of how to do it ? :)

New Guy

Re: Tutorial on many-to-many relations DB in VB.net

Posted: Thu Jun 16, 2011 12:42 pm
by Dummy1912
Hi New Guy,

Hmmm to be honest i have always work with a .mdb database
But ill try to find my old project i created before i learned about .mdb :D
i don't promise anything.

Dummy1912

Re: Tutorial on many-to-many relations DB in VB.net

Posted: Thu Jun 16, 2011 12:54 pm
by Dummy1912
Hi New Guy,

Well i have found a old one :D
i ever made in vb 2003 yea old :p

Okay to be sure this is what you want i add a small Picture so tell me thats what you want.

Dummy1912

Re: Tutorial on many-to-many relations DB in VB.net

Posted: Fri Jun 17, 2011 8:18 am
by NewGuy
Hi Dummy1912,

thank you for your answer ... but thats not quite what i had in mind :)

see .. you use only 2 tables .... and i think thats not enough .. since its a many-to-many reation .. i think 3 is needed

- many people can participate in one training session
- one person may have participated in many training sessions

i have now made the DB in vb.net ... and have a working DB .. and i made a picture of how i am doing the relations (see attachment : DatabaseAndRelations.jpg)

but this picture doesnt show where the relations are going ... so i made a picture of that too ... the 2 pics are identical .. just the one shows better the relationships in the DB

i just dont know how to get the DB/tables showing up on forms from the different relations

Re: Tutorial on many-to-many relations DB in VB.net

Posted: Fri Jun 17, 2011 10:58 am
by Dummy1912
Hi New Guy,

blusho; mine was only a example you know :D

how many tables you want thats up to you ;)

and i don't know if you made a connection already on your form?
if you have you can use this to load the database.
Code: Select all
'this will come in the form_load
DA.Fill(Ds1, "Agent")

'DA = a OleDbDataAdapter what name you want :D i call my DA
'Ds1 = a Public Class you will see this when you made your database i hope
'Agent is the table from the database
if you use a datagrid you must configurate it first
you will see right the Properties
go there and look for : DataMember

add there the Agent or whatever you need from a table.

then DataSource add there : Ds1

Good Luck
if you still can't find it or still have trouble
maybe i need to pm you my example :(

Dummy1912

Re: Tutorial on many-to-many relations DB in VB.net

Posted: Fri Jun 17, 2011 12:48 pm
by NewGuy
Hi Dummy1912 .. i have made the DB connection already, that works fine

but i cant figure out how to populate the gridview with the correct data

Maybe it would be a good idea if i saw your DB example .. you are welcome to PM me :)

NewGuy