views:

103

answers:

3

I have 3 Tables:

  • Titles:

    • TitleId (int 6, primary key)
    • TitleName (varchar 50)
  • Authors:

    • AuthorId (int 6, primary key)
    • AuthorName (varchar 50)
  • AuthorsTitles (this is a junction table for Titles and Authors)

    • TitleId (int 6)
    • AuthorId (int 6)

There's a "many to many" relation: A Title may have many Authors, and an Author may have many Titles. This is why I need the junction table.

All I want is to get a Windows form with a ComboBox with Titles. The user selects a Title, and the Author or Authors of the selected Title will be listed in a ListBox.

I'm using Microsoft Visual C# Express Edition 2008 and SQL Server Express Edition 2008.

Thanks

+1  A: 

I don't have sample code but hope this link helps you.

Data Binding in .NET / C# Windows Forms

Gulzar
A: 

To set up a database connection in Visual Studio, see this.

For examples on how to bind a combobox to a field in a table, view this.

Michael Todd
A: 

Michael and Gulzar:

Thanks very much for your help, but what I need is something little different.

In your answer there is an "one to many relation" (one customer with many orders) followed by another "one to many relation" (one order with many order-details).

In my problem there is an "one to many relation" (one title has many authors) followed by a "many to many relation" each one of these authors has a name.

I want to select a TitleName (and its TitleId) in a Combobox, and with this TitleId try to find all the AuthorName's in the Authors Table through the junction Table AuthorTitle.

In other words: I select a book with many authors in my ComboBox and I want to see their names in the ListBox.

It looks very simple! But I can't get a code that solves this problem.