Solved

databindings with 4 tables - getting nightmare !

Posted on 2004-08-23
10
168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

726 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