views:

235

answers:

0

I have an odd session problem. I store a session in a global session class and access it on different pages. Anyway, most of my pages work fine except this one page which is really preplexing me. I set the session in one page and access it on the next for a SQL select / update /delete and with my FormView / GridView /Details View. Needless to say the value of the session refuses to work in the SQL parameter even though my code behind file writes this very session value correctly to screen each time from the global class file. The codebehind code is:

Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    'add check session set
    If Session("UserName") = "" Then
        Session("LogMsg") = "Login Required For Accessing Statement Details"
        Response.Redirect("~/default.aspx")
    End If

    Dim StatementID As Guid = ExpGlobal.StatementID 
    Response.Write("WIll NOT READ SESSION VALUE DEFAULT VALUE IS WRONG BUT FOR TESTING<BR>Correct Value Is<BR>From ExpGlobal IS</BR>")
    Response.Write(StatementID)


End Sub

Protected Sub AddExpenseFV_ModeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddExpenseFV.ModeChanged

    Me.AddExpenseFV.Visible = False
End Sub
Protected Sub AddExpenseDetail_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddExpenseDetail.Click
    Me.AddExpenseFV.Visible = True
    Me.AddExpenseFV.DefaultMode = FormViewMode.Insert
End Sub

End Class

The SQL Parameters are as follows:

<asp:SqlDataSource ID="ExpensesGV" runat="server" 
        ConnectionString="<%$ ConnectionStrings:expense2009ConnectionString %>" 

    SelectCommand="SELECT StatementExpense.ExpenseDate, StatementExpense.Amount, StatementExpense.Quantity, StatementExpense.Description, StatementExpense.ExpenseID, Expense.Expense, StatementExpense.StatementID FROM StatementExpense INNER JOIN Expense ON StatementExpense.ExpenseID = Expense.ExpenseID AND StatementExpense.ExpenseID = Expense.ExpenseID WHERE (StatementExpense.StatementID = @StatementID)" 
    InsertCommand="INSERT INTO StatementExpense(Quantity, ExpenseDate, Amount, Description, StatementID, ExpenseID) VALUES (@Quantity, @ExpenseDate, @Amount, @Description, @StatementID, @ExpenseID)">
        <SelectParameters>
            <asp:SessionParameter Name="StatementID" SessionField="StatementID" />
        </SelectParameters>
        <InsertParameters>
            <asp:Parameter Name="Quanity" />
            <asp:Parameter Name="ExpenseDate" />
            <asp:Parameter Name="Amount" />
            <asp:Parameter Name="Description" />
            <asp:Parameter Name="StatementID"/>
            <asp:Parameter Name="ExpenseID" />
        </InsertParameters>
    </asp:SqlDataSource>

<asp:SqlDataSource ID="statementExpense" runat="server" 
    ConnectionString="<%$ ConnectionStrings:expense2009ConnectionString %>" 



    SelectCommand="SELECT Statement.SubmittedDate, Statement.FromDate, Statement.ToDate, Statement.Purpose, Statement.StatusID, Statement.ClientID, Client.Name, Status.Status, Client.ClientID AS Expr1, Employee.EmployeeID, Employee.FirstName, Employee.LastName, Employee.ProjectID FROM Statement INNER JOIN Client ON Statement.ClientID = Client.ClientID AND Statement.ClientID = Client.ClientID INNER JOIN Status ON Statement.StatusID = Status.StatusID INNER JOIN Employee ON Statement.EmployeeID = Employee.EmployeeID AND Statement.EmployeeID = Employee.EmployeeID WHERE (Statement.StatementID = @StatementID) AND (Employee.ProjectID = @ProjectID)"  >
    <SelectParameters>  
        <asp:SessionParameter DefaultValue="" Name="StatementID" 
            SessionField="StatementID" />
        <asp:SessionParameter DefaultValue="110" Name="ProjectID" 
            SessionField="ProjectID" />
    </SelectParameters>

</asp:SqlDataSource>