0

由于某种原因,我无法检索“CustomerAlertCountTotal”中包含的值。

如果我使用 QueryBuilder (Visual Studio 2010) 运行查询,则会返回正确的行,包括 CustomerAlertCountTotal 的数字计数值/结果。

这是我的 SELECT 查询:

<asp:SqlDataSource ID="SqlDataSourceCustomerList" runat="server" 
    ConnectionString="REMOVED" 
    ProviderName="REMOVED" 
    SelectCommand="SELECT contact.id_contact, contact.cname, contact.caddress1, contact.caddress2, contact.caddress3, contact.caddress4, contact.caddress5, contact.cpostcode, contact.ctel, contact.cmobile, contact.cemail, contact.trading_id, contact.cposition, trading_name.trading_name, CustomerAlertCountTotal FROM contact INNER JOIN trading_name ON contact.trading_id = trading_name.id_trading_name LEFT JOIN (SELECT COUNT(AlertID) AS CustomerAlertCountTotal, AlertTradingID FROM customer_support_dev.customer_alerts) AS COUNT ON COUNT.AlertTradingID = contact.trading_id WHERE (CHAR_LENGTH(contact.cname) > 0) ORDER BY contact.cname">
</asp:SqlDataSource>

或者更容易阅读:

SELECT contact.id_contact, contact.cname, contact.caddress1, contact.caddress2, contact.caddress3, contact.caddress4, contact.caddress5, contact.cpostcode, contact.ctel, contact.cmobile, contact.cemail, contact.trading_id, contact.cposition, trading_name.trading_name, CustomerAlertCountTotal
FROM contact
INNER JOIN trading_name ON contact.trading_id = trading_name.id_trading_name
LEFT JOIN (SELECT COUNT(AlertID) AS CustomerAlertCountTotal, AlertTradingID
FROM customer_support_dev.customer_alerts) AS COUNT ON COUNT .AlertTradingID = contact.trading_id
WHERE (CHAR_LENGTH(contact.cname) > 0)
ORDER BY contact.cname

这就是我试图显示值的方式:

<asp:TemplateField HeaderText="CustomerAlertCountTotal" SortExpression="CustomerAlertCountTotal">
    <ItemTemplate>
        <em><%#Eval("CustomerAlertCountTotal")%></em>
    </ItemTemplate>
</asp:TemplateField>

如果我替换这个:

<em><%#Eval("CustomerAlertCountTotal")%></em>

有了这个:

<em><%#Eval("cemail")%></em>

然后我看到他们的电子邮件地址应该是总 CustomerAlertCountTotal 值,所以我知道页面代码本质上是正确的,但由于某种原因,似乎 CustomerAlertCountTotal 实际上没有被选为可用值 - 但它在 querybuilder 中显示计数结果很好??

4

0 回答 0