[英]SQL: ALIAS, INNER JOIN not working
I'm doing a school project where i need to do following in asp.net: 我正在做一个学校项目,需要在asp.net中执行以下操作:
Make a list of photoalbums with the number of images in each album. 列出一张相册,其中列出每张相册中的图像数量。
I keep getting an error when i try to open the page in my browser (Chrome/Windows): 尝试在浏览器(Chrome / Windows)中打开页面时,我总是收到错误消息:
Server Error in '/' Application.
“ /”应用程序中的服务器错误。
Incorrect syntax near 'Album'.
“专辑”附近的语法不正确。
Description: An unhandled exception occurred during the execution of the current web request.
说明:执行当前Web请求期间发生未处理的异常。 Please review the stack trace for more information about the error and where it originated in the code.
请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息。
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near 'Album'.
异常详细信息:System.Data.SqlClient.SqlException:“专辑”附近的语法不正确。
I suspect it has something to do with the SelectCommand and INNER JOIN. 我怀疑这与SelectCommand和INNER JOIN有关。
My database has 2 tables: "Album" and "Billeder" (which means images in danish). 我的数据库有2个表:“专辑”和“ Billeder”(表示丹麦语的图像)。
The table "Album" has following columns: 表“专辑”具有以下列:
The table "Billeder" has the following columns: 表“ Billeder”具有以下列:
Here is my code: 这是我的代码:
<asp:SqlDataSource ID="SqlDataAlbums" runat="server" ConnectionString='<%$ ConnectionStrings:ConnectionString %>' SelectCommand="SELECT Billeder.imgnavn AS billede Album.navn AS albums FROM [Billeder] INNER JOIN Album ON Album.Id = Billeder.fkAlbumId"></asp:SqlDataSource>
<table class="table table-striped">
<tr>
<th>Navn</th>
<th>Antal billeder i Albummet</th>
</tr>
<asp:Repeater ID="RepeaterAlbums" DataSourceID="SqlDataAlbums" runat="server">
<ItemTemplate>
<tr>
<td><%# Eval ("albums") %></td>
<td></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
Missing a comma between Billeder.imgnavn AS billede
and Album.navn AS albums
Billeder.imgnavn AS billede
和Album.navn AS albums
之间缺少逗号
SELECT Billeder.imgnavn AS billede, Album.navn AS albums
FROM [Billeder] INNER JOIN Album ON Album.Id = Billeder.fkAlbumId
Your SELECT
statement is missing a comma: 您的
SELECT
语句缺少逗号:
SELECT Billeder.imgnavn AS billede Album.navn
should be 应该
SELECT Billeder.imgnavn AS billede, Album.navn
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.