Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Problem looking up values by selecting value in combobox

Posted on 2006-05-28
14
Medium Priority
?
224 Views
Last Modified: 2010-04-23
Hello all,

I'm developping a database application and i'm having problems selecting values.
I have two tables
 TBLJOBS with fields JOB_ID, CLIENT_ID
and TBLCLIENTS with fields CLIENT_ID, NAME, ADDRESS,...
There is a one to many relation between TBLCLIENTS.CLIENT_ID and TBLJOBS.CLIENT_ID
In my form i want a combobox selecting JOB-ID.
After the JOB_ID is selected i want my client fields updated depending on CLIENT_ID field.
Can anyone help me out here?
0
Comment
Question by:JackUzi
  • 8
  • 4
  • 2
14 Comments
 
LVL 3

Expert Comment

by:GilesBathgate
ID: 16779659
Can you not use an SQL query to achive this?

Update TBLCLIENTS SET Name = 'newname', Address='....   WHERE JOB-ID = '...

0
 

Author Comment

by:JackUzi
ID: 16779695
There is only a relation on the CLIENT_ID field.
This is because there are more jobs for one client.
0
 
LVL 3

Expert Comment

by:GilesBathgate
ID: 16779708
ah ok.

Update TBLClients,a TBLJOBS,b SET a.Name='...', a.Address='...   WHERE a.CLIENT_ID=b.CLIENT_ID AND JOB_ID = '...
0
Technology Partners: 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

by:JackUzi
ID: 16779723
Do you also know how to put this in code in the combobox.selectedchanged event?
0
 

Author Comment

by:JackUzi
ID: 16779757
I think i was a bit confusing by saying i wanted to update my client fields.
On my form there are also databound textboxes to display the client data.
So when I select a job-ID then i would show the corresponding client that is related to that job.
0
 
LVL 34

Expert Comment

by:Sancler
ID: 16779898
Try code like this to bind your combobox

   ComboBox.DataSource = TBLJOBS
   ComboBox.DisplayMember = "JOB_ID"
   ComboBox.ValueMember = "CLIENT_ID"
   ComboBox.DataBindings.Add("SelectedValue", TBLCLIENTS, "CLIENT_ID")

You shouldn't then need any other code in any of the combobox event subs.  As a new JOB_ID is selected in the conbobox, the relevant CLIENT_ID becomes the combobox's new SelectedValue, and the last line of the code will shift the pointer in the TBLCLIENTS table to the appropriate record for that.

Roger
0
 

Author Comment

by:JackUzi
ID: 16779956
I'm getting an error on the line where i set the valuememeber to CLIENT_ID.
System.ArgumentException was unhandled
  Message="This causes two bindings in the collection to bind to the same property.
Parameter name: binding"
  ParamName="binding"
   
0
 
LVL 34

Expert Comment

by:Sancler
ID: 16780128
What other databinding code you do you have?

Roger
0
 

Author Comment

by:JackUzi
ID: 16780290
This code is run in the onload event of the form.

Me.TBLJOBSTableAdapter.Fill(Me.AeroSimulatorsDBDataSet.TBLJOBS)
        Me.TBLCLIENTTableAdapter.Fill(Me.DBDataSet.TBLCLIENT)
        cboJOB_ID.DataSource = Me.DBDataSet.TBLJOBS
        cboJOB_ID.DisplayMember = "JOB_ID"
        cboJOB_ID.ValueMember = "CLIENTID"
        cboJOB_ID.DataBindings.Add("SelectedValue", Me.TBLCLIENTBindingSource, "CLIENTID")

Then on the form I have textboxes where the databinding.text property is tblclient.client_name, tblclient_street, ...
0
 

Author Comment

by:JackUzi
ID: 16780330
OK, the problem was that i dragged the JOB_ID combobox from the datasources window on the form.
So all properties concearning databindings are allready filled in.

I removed them and runned the code like you sugested but nothing changes in the textboxes.
(Databindings).text property is set to tblclientbindingsource - clientName and so on.
Textboxes are dragged from the datasource window.
Is this correct?
0
 
LVL 34

Accepted Solution

by:
Sancler earned 600 total points
ID: 16781104
My apologies.  First for the delay in coming back - but it is Sunday evening where I am ;-)  Second for not checking which version of VB.NET you were on before I commented.  And third for misleading you that the link could be automatic by adding

        cboJOB_ID.DataBindings.Add("SelectedValue", Me.TBLCLIENTBindingSource, "CLIENTID")

That only works the other way round on a Many To One Relationship.

You can scrap that line and, instead, in cboJOB_IDSelectedIndexChanged put

        TBLCLIENTBindingSource.Filter = "CLIENTID = " & cboJOB_ID.SelectedValue

I think the terminology in that is right - I've tried to take it from the object names your code uses - but you need to check it.  The basic idea is what you need.  That is, use the CLIENTID obtained from the jobs combobox to apply a filter to the information displayed about the client.

I hope that hasn't held you up too much.

Roger
0
 

Author Comment

by:JackUzi
ID: 16782249
Thanks Roger
I was searching for this answer for a few days now and you provided me the answer.
Now I can finally get to the other stuff.

By the way, Don't you know some interesting web links about database programming, because I'm new to VB.NET development and I don't understand that databinding issue so good.

Thank you
0
 
LVL 34

Expert Comment

by:Sancler
ID: 16782901
Have a look at some of the hits on this search string

http://www.google.co.uk/search?hl=en&q=databinding+example+Northwind+vb.net+2005&btnG=Search&meta=

There's a sample database - Northwind, another one is Pubs (short for publishers, not licensed premises) - that MS provides for free and many articles/examples use that for illustration.  So mention of it in a search will usually throw up stuff you can actually try out to see what's happening.

If you want a more rounded approach/description then I find the section Headed "Displaying Data on Forms in Windows Applications" in the Help File a good starting point.

Roger
0
 

Author Comment

by:JackUzi
ID: 16783561
thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…

572 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