Click here to Skip to main content
15,889,200 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I have 15 comboboxes on my form. They are all linked to the same column in my database.

eg

my database is called: NightshiftDB

Colums: Callsign
Crewname
CrewContact
CrewPhone

I have set up my comboboxes to show the "callsign"

But when I try to select, for example, call sign 650 in the first combobox and say callsign 710 in the next all the comboboxes change to the same callsign.

I am using VB and sql

Any help with this would be fantastic.

Diane

What I have tried:

I have looked at multiple solutions to this problem but am totally confused as they all seem to disagree with each other and nothing I have tried has worked.

VB
Dim copytable_1 As DataTable
        copytable_1 = NightshiftDBDataSet.Tables("callsign").Copy
        ComboBox2.DataSource = copytable_1


I tried the above in the formload event (I thought I could do this for each of the comboboxes) but it threw up the following error


System.NullReferenceException: 'Object reference not set to an instance of an object.'

System.Data.DataTableCollection.this[string].get returned Nothing


I'm not sure what this means, or how to fix it.
Posted
Updated 25-Apr-17 7:16am
v3
Comments
Dave Kreskowiak 23-Apr-17 19:34pm    
What does your code look like where you retrieve the data and bind the controls to it?
[no name] 23-Apr-17 19:45pm    
I tried finding your code in your "question" so we could see what might possibly the problem but nothing I tried worked.
Richard Deeming 25-Apr-17 15:25pm    
The NullReferenceException is quite clear: your NightshiftDBDataSet does not contain a table called "callsign".

Debug your code and examine the NightshiftDBDataSet.Tables collection to see what the table is actually called.

1 solution

If you bind several controls to the same column AND same record, they will all synchronously show the same value because they all are bound to the same source. Think there's a problem in your understanding of databases, records and bound controls - you should read more docu about this.

To keep the controls separated, you have to bind each control to an own dataadapter containing a different record (you may choose different records by adding a WHERE clause each dataadapter's SELECT command to point to a unique value - e.g. the primary key).
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900