[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


databindings with 4 tables - getting nightmare !

Posted on 2004-08-23
Medium Priority
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 !

Question by:fcomte
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
LVL 18

Expert Comment

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.  :))


Author Comment

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
LVL 18

Expert Comment

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)

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

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 ?
LVL 18

Accepted Solution

DotNetLover_Baan earned 2000 total points
ID: 11880203
Use,  ListBox1.DataSource = Nothing... then set the source again.It will reset the listBox.

Author Comment

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 ?


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 !!!


Author Comment

ID: 11955390

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 :(

Author Comment

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

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

649 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