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.

3
  • Can you post some of the records so we can see why the data is failing? Oct 10, 2013 at 19:08
  • Apologies I posted to early. The dropdown passes the value from a settings table to the master/history table, the values the settings table use are below as well as the dataset it uses to find the values. <asp:SqlDataSource ID="OKNGSelect" runat="server" ConnectionString="<%$ ConnectionStrings:BladeTracker %>" SelectCommand="SELECT col1, col2 FROM Settings WHERE (col2 = 3) OR (col2 = 4) ORDER BY col2"> </asp:SqlDataSource> Blade 1 Die 2 NG 4 OK 3
    – user2235420
    Oct 10, 2013 at 19:16
  • You just posted the datasource... can you post some of the SQL records with headers? Oct 10, 2013 at 19:18

1 Answer 1

0

Run your query in DESC order and look at the Edge1 column. Do all those values match the values in the query populating your DropDownList? I suspect not, and I imagine the reason why you don't get your exception when sorted ASC that first value DOES match a value in the DropDownList. Try this query to see if there are any rows where Edge1 doesn't exist in your Settings table:

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))

I should point out that in your DropDownList you have DataValueField="col1". Since you are pulling both col1 and col2 in your query, did you mean for this to be col2?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.