-1

I have a page (Order.aspx) which displays an order which has a specific FileNo, below I call this page from my (Default.aspx):

    LinkButton clickedButton = (LinkButton)sender;
    Session["FileNo"] = clickedButton.Text;
    Response.Redirect("~/Order.aspx");

In this order page there is a gridview control with the following sqldatasource, the below Datasource was successfully working and updating the database, but suddenly it started to update the database with null FileNo. I don't understand when does my Session["FileNo"] gets cleared. I can provide any extra code requested.

<asp:SqlDataSource ID="sds_OrderDetail" OnSelected="sds_OrderDetail_Selected" runat="server"
    ConnectionString="<%$ ConnectionStrings:MyDbConn %>" DeleteCommand="DELETE FROM [OrderDetail] WHERE [RowNo] = @RowNo"
    InsertCommand="INSERT INTO [OrderDetail] ([FileNo], [PONumber], [MaterialCode], [MaterialDescription], [MaterialCategory], [UnitOfMeasure], [Quantity], [ContainerType], [LoadingDate]) VALUES (@FileNo, @PONumber, @MaterialCode, @MaterialDescription, @MaterialCategory, @UnitOfMeasure, @Quantity, @ContainerType, @LoadingDate)"
    SelectCommand="SELECT * FROM [OrderDetail] WHERE ([FileNo] = @FileNo)" UpdateCommand="UPDATE [OrderDetail] SET [FileNo] = @FileNo, [PONumber] = @PONumber, [MaterialCode] = @MaterialCode, [MaterialDescription] = @MaterialDescription, [MaterialCategory] = @MaterialCategory, [UnitOfMeasure] = @UnitOfMeasure, [Quantity] = @Quantity, [ContainerType] = @ContainerType, [LoadingDate] = @LoadingDate WHERE [RowNo] = @RowNo">
    <SelectParameters>
        <asp:SessionParameter DefaultValue="-1" Name="FileNo" SessionField="FileNo" Type="Int32" />
    </SelectParameters>
    <DeleteParameters>
        <asp:Parameter Name="RowNo" Type="Int32" />
    </DeleteParameters>
    <InsertParameters>
        <asp:Parameter Name="FileNo" Type="Int32" />
        <asp:Parameter Name="PONumber" Type="String" />
        <asp:Parameter Name="MaterialCode" Type="String" />
        <asp:Parameter Name="MaterialDescription" Type="String" />
        <asp:Parameter Name="MaterialCategory" Type="String" />
        <asp:Parameter Name="UnitOfMeasure" Type="String" />
        <asp:Parameter Name="Quantity" Type="Int32" />
        <asp:Parameter Name="ContainerType" Type="String" />
        <asp:Parameter Name="LoadingDate" Type="String" />
    </InsertParameters>
    <UpdateParameters>
        <asp:Parameter Name="FileNo" Type="Int32" />
        <asp:Parameter Name="PONumber" Type="String" />
        <asp:Parameter Name="MaterialCode" Type="String" />
        <asp:Parameter Name="MaterialDescription" Type="String" />
        <asp:Parameter Name="MaterialCategory" Type="String" />
        <asp:Parameter Name="UnitOfMeasure" Type="String" />
        <asp:Parameter Name="Quantity" Type="Int32" />
        <asp:Parameter Name="ContainerType" Type="String" />
        <asp:Parameter Name="LoadingDate" Type="String" />
        <asp:Parameter Name="RowNo" Type="Int32" />
    </UpdateParameters>
</asp:SqlDataSource>
HOY
  • 1,067
  • 10
  • 42
  • 85

2 Answers2

1

Code does not stop working suddenly. There must be something (even if its very small) that made it to not work anymore. Here are a few things you can try to figure out where the problem is.

  1. Try to comment out things that you changed since it was working last time and start to un-comment code with minimum changes.

  2. Find all occurances of Session and Session["File"] in the entire solution and put a breakpoint on every occurance and debug through your application to see where exactly it loses its value.

  3. If you do not want FileNo to be a null, change the table structure in SQL and don't allow nulls in it. It adds an extra layer of validation and makes sure that there no corrupt data makes it to the database. At the end of the day, it is about the data being valid.

MaxDataSol
  • 358
  • 1
  • 2
  • 18
  • Yes, this was pretty same to the sequence of things that I have done, plus 4th asking in stackoverflow – HOY Aug 14 '12 at 10:39
  • 1
    There is another thing you can try to debug it. Try writing to a completely new session variable. Call it FileNoTest and see if it retains the value. This will give you a better indication of whether the problem is that the whole session is being refreshed for some reason or is it just FileNo that is being refreshed. – MaxDataSol Aug 14 '12 at 10:42
0

Other than select parameters, all the other parameters should include FileNo as SessionParameter, Session["FileNo"] is not cleared, it was not used.

HOY
  • 1,067
  • 10
  • 42
  • 85