Solved

databindings with 4 tables - getting nightmare !

Posted on 2004-08-23
10
164 Views
Last Modified: 2010-04-23
Hello everybody ! Here is my terrible problem :

VB.NET 2003 / Access 2003

I must write a program who can managed a timetable for several companies.
The tables are : Companies (Key = ID), Persons (Key = ID from Company + ID from Person), TimeTable (...), TimeTableDetails (...).
My program must work with forms in which datas are coming from more than one table.
For instance, the form "FrmPerson" has a combobox where you select the Company, then the persons from the company selected (linked by a foreign key in the table Person) must fill a ListBox (Name + Surname). I must be able to navigate through the companies, and the listbox must refresh with the persons from that company. The datas of a person must then be placed in several TextBox (adress, phone, ...).

I must be able to modify a person (name, adress, ...), delete a person or add one.
The others forms are based on 3 tables (Company + Person + TimTable), but i think if i can do one form, it should be ok.
Ma bigbigbig problem is that i'm learning vb.net, and i have a very small time for doing this code.... i tried the assistant, but then i dont understand what to do with my combobox linked with my listbox linked with my textboxes.

What i need is a small sample of code which shows how to link these 3 controls, all based on the same Access connection.

Many many thanks for your help !

Fred
0
Comment
Question by:fcomte
  • 5
  • 3
10 Comments
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11875904
cool... you have got a lot of things to do... but believe me.. it is damn easy...  Use DataSet... thats it... it will take care of everything. Selection, insert, delete, update... anything you want.
Briefly what you have to do is:
Create and fill a dataset using DataAdapter with proper sql SELECT query.
Bind all the controls to the coresponding fields of the table with the help of Dataset.

This is the basic idea. I suggest you NOT to go for drag and drop data controls. Create them through code. You will find thousands of help pages on "OleDb" Ado.Net. Start working on it... we are here to help you.  :))

-Baan
0
 
LVL 1

Author Comment

by:fcomte
ID: 11876005
Hello Baan,

In fact, i have already written a lot of code ;), and i use exactly what you're talking about. I think i wont use the wizard, because i dont understand what does the generated code do...
Ok, my dataset is filled on a query which returns the persons from an ID company. So first question : how do i link the listbox (which contains the person's name+surname, so 2 fields) to the combobox (which contains the Companies) ?
Second question : how do i link the Textboxes (adresse for instance) to the person selected in the listbox ? I dont know if i have to use the ValueMember property or else ?!?

As u say... there are TOO many pages written, i just didn't find exactly what i want to do...

Thx, Fred
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11876101
ok.. for binding the ListBox with full name ( name+surname), modify the SELECT statement. eg:
SELECT CONCAT(name,' ',surname) AS FullName,...
Then after filleng the dataset, bind the FullName field to the ListBox
ListBox1.DisplayMember = "FieldName"
ListBox1.DataSource = DS.Tables(0)

-Baan
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 1

Author Comment

by:fcomte
ID: 11879206
Ok, i have a dataset on the combobox "Companies", filled on the Form_Load.
Then i have another dataset on the listbox "Persons", filled on the ComboBox1_SelectedIndexChanged. Problem is, i want to clear the items of the listbox when i select another item in the combobox (normal...).
I wrote "Me.LstPersons.Items.Clear()", but at runtime, i get the error "can't modify items collection when datasource property is defined"...
How to delete the items in the listbox when the combox is refreshed ?
0
 
LVL 18

Accepted Solution

by:
DotNetLover_Baan earned 500 total points
ID: 11880203
Use,  ListBox1.DataSource = Nothing... then set the source again.It will reset the listBox.
0
 
LVL 1

Author Comment

by:fcomte
ID: 11883573
Thx, that's what i did...
But i feel like basically my dataadapters and dataset are wrong created...
What is the best in this situation :

A combobox filled with the Company Names = a dataadapter + a dataset on the query
        rqt = "SELECT T_Entite.Ent_ID, T_Entite.Ent_Nom"
        rqt &= " FROM T_Entite;"

A listbox filled with the Persons Name = another dataadapter + a dataset on the query
        rqt = "SELECT T_Personne.Per_ID, T_Personne.Per_Nom, T_Personne.Per_Prenom"
        rqt &= " FROM(T_Personne)"
        rqt &= " WHERE (((T_Personne.Per_Lien)=" & Me.CmbEntite.SelectedValue.ToString & "));"  (where CmbEntite is the combox)

And then a third dataadapter and a third dataset for all the textboxes filled with personnal datas ?

OR

should i have ONE datadapter for the 3 tables (how to write the query with the relations ?) and 3 datasets or only one ?

Thank you for your help !!!

Fred
0
 
LVL 1

Author Comment

by:fcomte
ID: 11955390
Hi,

All right, i knew my question not a good one ;) I've read a lot and now my soft is "living".
I used one dataadapter which source change everytime i want to put a table in my dataset. My comboboxes and listboxes are dynamically built, using a dataview (RowFilter property => ValueMember / SelectedIndexChanged).

My problem is now :

How to refresh the combo or listboxes, when an entry is deleted for instance. I tried with a .reset on the dataset, or a .refresh on the combox, but everytime i have a splendid error like "Index 0 is not positive and below the total numberof lines"... what to do ?!?

For the rest of the soft... everything's fine (lot of theory before work !). Only this refresh thing, which makes me very angry :(
0
 
LVL 1

Author Comment

by:fcomte
ID: 12154568
To Admin : Can u close this question, I have resolved it myself (with a little help from DotNetLover_Baan, thank u !)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question