我已将以下代码设置为在 Gridview 中显示 player1 v player2。但是,它当前显示 tblFixtures.player1 v tblFixtures.player2 是 UniqueIdentifiers,我需要它来显示它们对应的联系人姓名。tblaccounts 有 accountID(uniqueidentifier) 和 contactName(varchar) 列,但不确定如何以这样的方式加入它,以便我可以在下面的 Gridview 中显示它们。
<asp:SqlDataSource ID="DSFixtures" runat="server" ConnectionString="
<%$ ConnectionStrings:DBConnectionString %>" SelectCommand="SELECT
tblFixtures.player1, tblFixtures.player2, tblFixtures.compID,
tblFixtures.round
FROM tblFixtures INNER JOIN tblCompetitions ON tblFixtures.compID =
tblCompetitions.compID WHERE tblFixtures.compID = @Event_ID and round =
@Round ">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="compID" Name="Event_ID" />
<asp:QueryStringParameter QueryStringField="round" Name="Round" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Gridview ID="gdvFixtures" visible="false" width="100%"
runat="server" AllowPaging="True" AutoGenerateColumns="False"
CssClass="mGrid" DataKeyNames="compID" DataSourceID="DSFixtures"
PageSize="20" AllowSorting="True">
<AlternatingRowStyle CssClass="alt" />
<Columns>
<asp:BoundField DataField="player1" HeaderText="player1" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
V
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="player2" HeaderText="player2" />
</Columns>
</asp:GridView>
您可以进行嵌套选择
SELECT tblFixtures.player1, (SELECT name FROM tblaccounts WHERE
(accountID = tblFixtures.player1)) AS player1_name, ...
或者再创建 2 个连接,每个玩家一个。您可以通过重命名表来做到这一点,AS
这样您就可以多次加入同一个表。
INNER JOIN tblaccounts AS acc1 ON acc1.accountID = tblFixtures.player1 INNER JOIN
tblaccounts AS acc2 ON acc1.accountID = tblFixtures.player2
更新
您的整个查询应如下所示。而player1_name
与player2_name
成为你可以在GridView使用的列名。
SELECT
tblFixtures.player1,
(SELECT name FROM tblaccounts WHERE (accountID = tblFixtures.player1)) AS player1_name,
tblFixtures.player2,
(SELECT name FROM tblaccounts WHERE (accountID = tblFixtures.player2)) AS player2_name,
tblFixtures.compID,
tblFixtures.round
FROM tblFixtures INNER JOIN tblCompetitions ON tblFixtures.compID =
tblCompetitions.compID WHERE tblFixtures.compID = @Event_ID and round =
@Round
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句