如何在Sql Compact上连接表?
我有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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来你正在参加自己的节目。我认为你的意思是这样做:
It looks like you were joining shows on itself. I think you were meaning to do this: