locked
"Cannot find column [XXX]" when first gridview filtered but no errors retrieving details if unfiltered RRS feed

  • Question

  • User976784755 posted

    Greetings. 

    I'm creating an inventory ordering system (2 tables: orders & orders_details, joined by order_nbr field).  The first gridview (orders) has a select button that opens a second gridview (order details) by order_nbr.  If the first gridview is unfiltered (from a search criteria form), the second gridview displays the products ordered.  However, if the first gridview is filtered (by date, customer, etc.), I get runtime error: "cannot find column [customer]".  I don't see how filtering the first gridview has any relevance to retrieving and binding the data for the second gridview.  

    Any suggestions greatly appreciated. 

    Added ASPx & VB CODE:

    <section id="SUPPLIES_RESULTS" runat="server" style="display:none">
    <div style="background-color:#b0b0b0; width:810px; margin:0 auto;">
    <asp:GridView ID="supResults" runat="server" AllowPaging="True" AutoGenerateColumns="false"
    DataSourceID="DS2"
    OnRowUpdated="supClearSQLcrit"
    Font-Size="16px" Height="20px" HorizontalAlign="Left" Width="810px" BackColor="White" PageSize="25" CellPadding="3"
    OnSelectedIndexChanged="GetOrder"
    AllowSorting="True" DataKeyNames="ID"
    AutoGenerateSelectButton="True"
    style="text-align:center">
    <Columns>
    <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" readonly="true" itemstyle-width="15%"/>
    <asp:BoundField DataField="ORDER_NBR" HeaderText="Order Number" SortExpression="ORDER_NBR" itemstyle-width="15%" readonly="true" />
    <asp:BoundField DataField="ORDER_DT" DataFormatString ="{0:d}" HeaderText="Date Submitted" SortExpression="ORDER_DT" itemstyle-width="20%" readonly="true"/>
    <asp:BoundField DataField="FULFILLMENT_DT" DataFormatString ="{0:d}" HeaderText="Date Fulfilled" SortExpression="FULFILLMENT_DT" itemstyle-width="20%"/>
    <asp:BoundField DataField="REQUESTOR" HeaderText="Submitted By" SortExpression="Requestor" itemstyle-width="20%"/>
    </Columns>
    <HeaderStyle ForeColor="Black" />
    <PagerStyle Font-Size="12pt" />
    </asp:GridView>
    </div>
    </section>

    <section id="SUPPLIES_DETAILS" runat="server" style="display:none">
    <div style="background-color:#b0b0b0; width:810px; margin:0 auto;">
    <asp:GridView ID="gvOrderDetails" runat="server" AllowPaging="True"
    AutoGenerateColumns="false"
    AutoGenerateEditButton="true"
    DataKeyNames="ID"
    DataSourceID="DS3"
    OnRowUpdated="supClearSQLcrit"
    OnRowCommand="supDetailsRowCmd"
    Font-Size="16px" Height="20px" HorizontalAlign="Left" Width="810px" BackColor="White" PageSize="25" CellPadding="3"
    AllowSorting="True"
    style="text-align:center">
    <Columns>
    <asp:TemplateField ShowHeader="False">
    <ItemTemplate>
    <span onclick="return confirm('Do you really want to delete item?')"/>
    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
    CommandName="DeleteItem" Text="Delete"></asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" itemstyle-width="10%" readonly="true" />
    <asp:BoundField DataField="ORDER_NBR" HeaderText="Order Number" SortExpression="ORDER_NBR" itemstyle-width="15%" readonly="true" />
    <asp:BoundField DataField="LINE_NBR" HeaderText="Line Number" SortExpression="LINE_NBR" itemstyle-width="15%" readonly="true" />
    <asp:BoundField DataField="ITEM" HeaderText="Item Description" SortExpression="ITEM" itemstyle-width="35%" />
    <asp:BoundField DataField="QTY" HeaderText="QTY" SortExpression="QTY" itemstyle-width="5%" />
    <asp:BoundField DataField="PACKAGING" HeaderText="Packaging" SortExpression="PACKAGING" itemstyle-width="10%" />
    </Columns>
    <HeaderStyle ForeColor="Black" />
    <PagerStyle Font-Size="12pt" />
    </asp:GridView>
    </div>
    </section>


    <asp:SqlDataSource id="dsPRODUCT" runat="server" ConnectionString="<%$ ConnectionStrings:aspJAIL %>"
    SelectCommand="SELECT [PRODUCT] FROM [ORDER_PRODUCT] ORDER BY [PRODUCT]"></asp:SqlDataSource>

    <asp:SqlDataSource ID="DS2" runat="server" ConnectionString="<%$ ConnectionStrings:aspJail %>"
    SelectCommand="SELECT * FROM [ORDER_SUMMARY]"></asp:SqlDataSource>

    <asp:SqlDataSource ID="DS3" runat="server" ConnectionString="<%$ ConnectionStrings:aspJail %>"
    SelectCommand="SELECT * FROM [ORDER_DETAILS]"></asp:SqlDataSource>

    VB:

    Protected Sub GetOrder(sender As Object, e As EventArgs)

    Literal1.text = "Inventory Order Details"

    Dim KEY As String
    KEY = supResults.SelectedRow.Cells(2).Text

    'StrSqlQuery = "SELECT * From dbo.order_details WHERE ORDER_NBR = " & KEY

    'Literal1.text = StrSqlQuery

    StrSqlQuery = "SELECT * From dbo.order_details"

    DS3.SelectCommand = StrSqlQuery
    'gvOrderDetails.DataSourceID = "DS3"
    gvOrderDetails.DataBind()

    Friday, June 9, 2017 1:13 PM

All replies

  • User-1838255255 posted

    Hi Gregory.j.patti,

    According to your description, as far as I know, about this issue, maybe caused by you want to use this field, but can't find this column.

    I notice that you don't use this column in your Gridview, I am not clear you how to filter the datasource of gridview1. Also I suggest you could try use date to filter, if it success. please check if exist 'customer' in the datasource, also please check the spell of this field.

    Here is a tutorial about how to filter the datasource, please check:

    SqlDataSource.FilterExpression Property:

    https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.filterexpression(v=vs.110).aspx 

    Also I hope you could post the filter code and specify operations(detail error message and which line code or what operate caused this error), this will better help you!

    Best Regards,

    Eric Du

    Tuesday, June 13, 2017 3:27 AM