Solved

Combobox table lookup

Posted on 2006-07-14
6
235 Views
Last Modified: 2010-04-23
Hi guys.

This is a simple one but can't get it to work.

VB.net with an Access Database.

I have a customer table with a marketing ID field (type: number) and this links to a Marketing table which also has a MarketingID field (type: Autonumber) and a Marketing field. I now have a form in VB.net for entering new customers and viewing exsiting. This form did contain an oleDataAdapter with the query "SELECT * FROM Customer" and a dataset dsCustomer1 and I could enter info for the customer.

I now want to allow the user to enter where the customer heard about us via a combobox and a link to this Maketing table. This will contain "TV, radio, press ...". How do I do this.

Do I create another oleDataAdapter with the query "SELECT * FROM Marketing" and add this to a new or existing dataset. Or do I merrge this query with the existing one using JOIN or WHERE??? I've had a go and also have heard of this datarelation object I should be using which I can't remember from VB 6.

Many thx

0
Comment
Question by:adampdarcy
  • 2
  • 2
6 Comments
 
LVL 6

Expert Comment

by:manch
ID: 17106996


Use the existing Data set

and use the combobox properties (DataSource, DisplayMember, ValueMember properties )

0
 
LVL 24

Accepted Solution

by:
Jeff Certain earned 125 total points
ID: 17107614
You can either add the table to the existing dataset, or you can create a new table. Since you're not going to be creating datarelation objects, you really don't need the overhead of the dataset; it's just a convenient way to group tables.

You ought to avoid using *; instead you should explicitly state what fields you want. This has a few effects.
1. More efficient queries, since the database engine doesn't need to look up your field names to resolve the *.
2. Transferring less data since, often, you don't need every column in the table.
3. It results in a consistent query. You shouldn't really be using positional references to your columns, but the order of coumns in a datagrid, for example, will change if the columns are autogenerated and you make database table changes.

To be more specific about the syntax for the combo box binding:

    With myComboBox
      .DataSource = ds.Tables("Marketing")
      .DisplayMember = "MarketingType"
      .ValueMember = "MarketingId"
    End With
0
 

Author Comment

by:adampdarcy
ID: 17107785
This I have tried with no success.

I've got two data adapters, one for each table, and have put them both in the same dataset.

The combobox simply displays nothing?
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 17107839
Code please? Specifically, where you create the adapters and fill the tables.
0
 

Author Comment

by:adampdarcy
ID: 17108456
I havn't written it it in code as I've used the dataAdapter tools in the form designer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now