Solved

Combobox table lookup

Posted on 2006-07-14
6
234 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
GridDataView 6 46
Total in textboxes 9 36
Form design in vb.net 7 21
Visual Studio editor? 1 19
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 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

11 Experts available now in Live!

Get 1:1 Help Now