如何在Sql Compact上连接表?

发布于 2024-10-18 04:50:32 字数 921 浏览 4 评论 0原文

我有2个表数据库;

第一个表的列;

ClubID(主键,自动递增),ClubName

第二个表的列;

ShowID(主键,自动递增),ShowDate,ClubID

用户是在表格上选择俱乐部名称,当用户选择名称时,用户选择的表格上的日期必须列出在表格上。

这是代码;

SqlCeConnection Conn = new SqlCeConnection("Data Source=|DataDirectory|CeoDatabase.sdf;Password=CeoDB;Persist Security Info=True");
            Conn.Open();

            SqlCeCommand GetDates = new SqlCeCommand("SELECT ShowDate FROM Shows INNER JOIN Shows ON  Shows.ClubID = Clubs.ClubID WHERE Clubs.ClubName='" + cmb_ClubNamesList.SelectedItem.ToString() + "'", Conn);

            SqlCeDataReader WriteDates= RezervasyonlariAl.ExecuteReader();


            while (WriteDates.Read())
            {
               cmb_ClubNamesList.Items.Add(WriteDates["ShowDate"]);
            }

此代码在 SqlCeCommand GetDates 行上引发“表别名必须是唯一的。[重复别名的名称 = 显示]”异常。

I have 2 table database;

Firt table's columns;

ClubID(Primary key, auto-increment enabled), ClubName

Second table's columns;

ShowID(Primary key, auto-increment enabled), ShowDate, ClubID

User is selecting Club's name on the form, when user selected a name, dates on the table user have selected must be list on form.

Here is the code;

SqlCeConnection Conn = new SqlCeConnection("Data Source=|DataDirectory|CeoDatabase.sdf;Password=CeoDB;Persist Security Info=True");
            Conn.Open();

            SqlCeCommand GetDates = new SqlCeCommand("SELECT ShowDate FROM Shows INNER JOIN Shows ON  Shows.ClubID = Clubs.ClubID WHERE Clubs.ClubName='" + cmb_ClubNamesList.SelectedItem.ToString() + "'", Conn);

            SqlCeDataReader WriteDates= RezervasyonlariAl.ExecuteReader();


            while (WriteDates.Read())
            {
               cmb_ClubNamesList.Items.Add(WriteDates["ShowDate"]);
            }

This code throws "The table aliases must be unique. [ Name of duplicate alias = Shows ]" exception on the SqlCeCommand GetDates line.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨离汐 2024-10-25 04:50:32

看起来你正在参加自己的节目。我认为你的意思是这样做:

SELECT ShowDate FROM Shows INNER JOIN Clubs ON  Shows.ClubID = Clubs.ClubID WHERE Clubs.ClubName='" + cmb_ClubNamesList.SelectedItem.ToString() + "'"

It looks like you were joining shows on itself. I think you were meaning to do this:

SELECT ShowDate FROM Shows INNER JOIN Clubs ON  Shows.ClubID = Clubs.ClubID WHERE Clubs.ClubName='" + cmb_ClubNamesList.SelectedItem.ToString() + "'"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文