0

Evening SO,

I'm running in to the above error when trying to update a gridview with a drop down list. However, this only happens depending on how I arrange my dataset.

The following SQL gives me an error:

    "SELECT top 1 M.Title, H.* FROM MASTER AS M
    RIGHT JOIN History AS H
    ON M.TITLE = H.TITLE
    WHERE [Type] < '3'
    order by h.upd_date_time desc"

However, if I remove the 'desc' from the script then the web page will work without error. For reference I'm using the following script for the DDL:

            <asp:TemplateField HeaderText="Edge 1" SortExpression="Edge1">
            <EditItemTemplate>
            <asp:DropDownList 
             ID="DDL1" runat="server" DataSourceID="OKNGSelect" DataTextField="col1" 
             DataValueField="col1" SelectedValue='<%# Bind("Edge1") %>' AppendDataBoundItems="true">
             <asp:ListItem Text="Select" Value="" />
            </asp:DropDownList>
            </EditItemTemplate>
            <ItemTemplate>
            <asp:Label ID="Label1" runat="server" Text='<%# Bind("Edge1") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle Wrap="False" />
        </asp:TemplateField>

Is there a way to fix this at the SQL side as I need the most recent record to display from my history table on its own? I've tried fixing it from the asp page side but after some extensive research on the net it seems this is an uncommon but very elusive fault to deal with.

Thanks.

4

1 回答 1

0

按 DESC 顺序运行查询并查看该Edge1列。所有这些值是否与填充您的查询中的值匹配DropDownList?我怀疑不是,我想为什么在排序 ASC 时没有得到异常的原因是第一个值与 DropDownList 中的值匹配。尝试此查询以查看设置表中是否存在 Edge1 不存在的行:

SELECT M.Title, H.* 
    FROM MASTER AS M RIGHT JOIN History AS H
        ON M.TITLE = H.TITLE
    WHERE [Type] < '3'
        AND Edge1 NOT IN (SELECT col1 FROM Settings WHERE (col2 = 3) OR (col2 = 4))

我应该指出,在你的DropDownList你有DataValueField="col1"。由于您在查询中同时拉取 col1 和 col2,您的意思是它是 col2 吗?

于 2013-10-10T19:22:41.453 回答