我有一个列表视图,它显示来自和 sql 服务器视图的记录。数据按 customerid 过滤,并在运行视图时具有 2 条唯一记录。然而,列表视图将只显示第一条记录,并显示两次。所以列表视图中显示了两条记录,但它没有显示视图生成的两条记录,它只是在视图中显示了第一条记录两次。我希望这很清楚。
到底是怎么回事?我一直在寻找几个小时没有运气。
<asp:ListView ID="lstBeforeAfter" runat="server" DataKeyNames="CustomerID" InsertItemPosition="None">
<LayoutTemplate>
<div class="divreg">
<table ID="itemPlaceholderContainer" runat="server" cellpadding="2" class="tablebasic" style="vertical-align:top">
<tr ID="Tr1" runat="server" align="center">
<td style="background-color:#7e0d7d; color:White; font-size:1.2em; font-weight:bold; padding-top:4px; padding-bottom:4px">
Services
</td>
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</div>
</td>
</LayoutTemplate>
<ItemTemplate>
<tr style="">
<td align="center">
<div class="divwrap">
<div class="left3ColHeader">
<b>Date</b>
</div>
<div class="mid3ColHeader">
<b>Stylist</b>
</div>
<div class="right3ColHeader">
<b>Services</b>
</div>
<div class="formclear">
</div>
<div class="left3ColBorder">
<%# Eval("SchedStartDateTime", "{0:d}")%>
</div>
<div class="mid3ColBorder">
<%#Eval("FullName")%>
</div>
<div class="right3ColBorder">
<%#Eval("ServiceText")%>
</div>
<div class="formclear">
</div>
<div class="left2ColHeader">
<b>Before Picture</b>
</div>
<div class="right2ColHeader">
<b>After Picture</b>
</div>
<div class="formclear">
</div>
<div class="left2ColPicBorder">
<asp:Image ID="imgLeft" ImageUrl='<%# Eval("BeforePicPath") %>' runat="server" />
</div>
<div class="right2ColPicBorder">
<asp:Image runat="server" ID="imgRight" ImageUrl='<%# Eval("AfterPicPath") %>' />
</div>
<div class="formclear">
</div>
<div class="left2ColBorder">
<asp:Label ID="lblBefore" Width="95%" runat="server" Text='<%# Eval("BeforePicName") %>'></asp:Label>
</div>
<div class="right2ColBorder">
<asp:Label ID="lblAfter" Width="95%" runat="server" Text='<%# Eval("AfterPicName") %>'></asp:Label>
</div>
<div class="formclear">
</div>
<div class="divreg">
<hr />
</div>
<div class="formclear">
</div>
</div>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr style="background-color:#ffffd9">
<td align="center">
<div class="divwrap">
<div class="left3ColHeader">
<b>Date</b>
</div>
<div class="mid3ColHeader">
<b>Stylist</b>
</div>
<div class="right3ColHeader">
<b>Services</b>
</div>
<div class="formclear">
</div>
<div class="left3ColBorder">
<%# Eval("SchedStartDateTime", "{0:d}")%>
</div>
<div class="mid3ColBorder">
<%#Eval("FullName")%>
</div>
<div class="right3ColBorder">
<%# Eval("ServiceText").ToString%>
</div>
<div class="formclear">
</div>
<div class="left2ColHeader">
<b>Before Picture</b>
</div>
<div class="right2ColHeader">
<b>After Picture</b>
</div>
<div class="formclear">
</div>
<div class="left2ColPicBorder">
<asp:Image ID="imgLeft" ImageUrl='<%# Eval("BeforePicPath") %>' runat="server" />
</div>
<div class="right2ColPicBorder">
<asp:Image runat="server" ID="imgRight" ImageUrl='<%# Eval("AfterPicPath") %>' />
</div>
<div class="formclear">
</div>
<div class="left2ColBorder">
<asp:Label ID="lblBefore" Width="95%" runat="server" Text='<%# Eval("BeforePicName") %>'></asp:Label>
</div>
<div class="right2ColBorder">
<asp:Label ID="lblAfter" Width="95%" runat="server" Text='<%# Eval("AfterPicName") %>'></asp:Label>
</div>
<div class="formclear">
</div>
<div class="divreg">
<hr />
</div>
<div class="formclear"> </div>
</div>
</td>
</tr>
</AlternatingItemTemplate>
</asp:ListView>
Protected Sub LoadPortfolio(ByVal iCustID As Integer)
Dim dc As New SalonDataClassesDataContext
Dim q = From p In dc.vClientStyles Where p.CustomerID = iCustID Order By p.SchedStartDateTime Descending Select p
If q.Count > 0 Then
Me.lstBeforeAfter.DataSource = q
Me.lstBeforeAfter.DataBind()
End If
End Sub
SELECT ISNULL(dbo.Services.ServiceID, 0) AS ServiceID, dbo.Schedules.SchedStartDateTime, dbo.Schedules.ServiceText, dbo.Schedules.CustomerID,
ISNULL(dbo.Services.Completed, 0) AS Completed, dbo.Stylists.FullName, dbo.Stylists.StylistID, ISNULL(dbo.Services.BeforePicName, 'No Title') AS BeforePicName,
ISNULL(dbo.Services.BeforePicPath, '../images2020/resume-photo.jpg') AS BeforePicPath, ISNULL(dbo.Services.AfterPicName, 'No Title') AS AfterPicName,
ISNULL(dbo.Services.AfterPicPath, '../images2020/resume-photo.jpg') AS AfterPicPath
FROM dbo.Schedules INNER JOIN dbo.Stylists ON dbo.Schedules.UserID = dbo.Stylists.UserID LEFT OUTER JOIN dbo.Services ON dbo.Schedules.ServiceID = dbo.Services.ServiceID
ORDER BY dbo.Schedules.SchedStartDateTime DESC
更改为联合查询,但 linq 不喜欢它。
SELECT ISNULL(dbo.Schedules.ServiceID, 0) AS ServiceID, dbo.Schedules.SchedStartDateTime, dbo.Schedules.ServiceText, dbo.Schedules.CustomerID,
ISNULL(dbo.Schedules.Completed, 0) AS Completed, dbo.Stylists.FullName, dbo.Stylists.StylistID, 'No Title' AS BeforePicName, '../images2020/resume-photo.jpg' AS BeforePicPath, 'No Title' AS AfterPicName, '../images2020/resume-photo.jpg' AS AfterPicPath
FROM dbo.Schedules INNER JOIN dbo.Stylists ON dbo.Schedules.UserID = dbo.Stylists.UserID
Where dbo.Schedules.CustomerID = 27
UNION
SELECT ISNULL(dbo.Services.ServiceID, 0) AS ServiceID, dbo.Schedules.SchedStartDateTime, dbo.Schedules.ServiceText, dbo.Schedules.CustomerID,
ISNULL(dbo.Services.Completed, 0) AS Completed, dbo.Stylists.FullName, dbo.Stylists.StylistID, ISNULL(dbo.Services.BeforePicName, 'No Title') AS BeforePicName,
ISNULL(dbo.Services.BeforePicPath, '../images2020/resume-photo.jpg') AS BeforePicPath, ISNULL(dbo.Services.AfterPicName, 'No Title') AS AfterPicName, ISNULL(dbo.Services.AfterPicPath, '../images2020/resume-photo.jpg') AS AfterPicPath
FROM dbo.Schedules INNER JOIN dbo.Stylists ON dbo.Schedules.UserID = dbo.Stylists.UserID INNER JOIN dbo.Services ON dbo.Schedules.ServiceID = dbo.Services.ServiceID
Where dbo.Schedules.CustomerID = 27 ORDER BY dbo.Schedules.SchedStartDateTime DESC
我现在得到错误...查询结果不能被多次枚举。
我究竟做错了什么?谢谢