如何让我的Windows窗体执行并显示我的数据库查询?

时间:2021-09-13 11:17:47

I have 3 Tables:

我有3个表:

  • Titles:

    • TitleId (int 6, primary key)
    • TitleId(int 6,主键)

    • TitleName (varchar 50)
    • TitleName(varchar 50)

  • 标题:TitleId(int 6,主键)TitleName(varchar 50)

  • Authors:

    • AuthorId (int 6, primary key)
    • AuthorId(int 6,主键)

    • AuthorName (varchar 50)
    • 作者姓名(varchar 50)

  • 作者:AuthorId(int 6,主键)AuthorName(varchar 50)

  • AuthorsTitles (this is a junction table for Titles and Authors)

    AuthorsTitles(这是标题和作者的联结表)

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

    • AuthorId (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.

我想要的是获得带有标题的ComboBox的Windows表单。用户选择标题,并且所选标题的作者或作者将列在ListBox中。

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

我正在使用Microsoft Visual C#Express Edition 2008和SQL Server Express Edition 2008。

2 个解决方案

#1


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

我没有示例代码,但希望此链接可以帮助您。

Data Binding in .NET / C# Windows Forms

.NET / C#Windows窗体中的数据绑定

#2


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.

要在Visual Studio中设置数据库连接,请参阅此。有关如何将组合框绑定到表中的字段的示例,请查看此内容。

#1


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

我没有示例代码,但希望此链接可以帮助您。

Data Binding in .NET / C# Windows Forms

.NET / C#Windows窗体中的数据绑定

#2


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.

要在Visual Studio中设置数据库连接,请参阅此。有关如何将组合框绑定到表中的字段的示例,请查看此内容。