Solved

Issue assigning a session variable to a sqldatasource

Posted on 2007-12-03
5
905 Views
Last Modified: 2008-02-01
I have a sqldatasource that is running an update statement. The update statment calls a sproc that updates the table. I have a 'LastModifiedBy' column in the table. I set a session variable  (userid) to what I want to go into the this column in the page_load event to make sure it's being set. I setup the sqldatasource's parameters to use that session variable to send to the proc to populate the 'LastModifiedBy' column but it never gets sent. If I hardcode the variable in the proc, everything works fine.

Thoughts?
0
Comment
Question by:KBSLPDev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 40

Expert Comment

by:evilrix
ID: 20399623
Are you sure the session variable exists at the point you use it? Do you check it for null to be use? Posting your code might be useful.
0
 

Author Comment

by:KBSLPDev
ID: 20399992
Pretty sure. However, since it's done declaratively, it's difficult to troubleshoot. Attached is the code. There is more but I think it's irrelavent. There is a 3rd party grid (infragistics) that invokes the update method. I do know the update method is being invoked so it should be out of the grid's hands at that point.
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        DeleteCommand="k_sp_Rules_D" DeleteCommandType="StoredProcedure" InsertCommand="k_sp_Rules_I"
        InsertCommandType="StoredProcedure" SelectCommand="k_sp_Rules_R" SelectCommandType="StoredProcedure"
        UpdateCommand="k_sp_Rules_U" UpdateCommandType="StoredProcedure" OnDeleted="SqlDataSource1_Deleted" OnUpdated="SqlDataSource1_Updated" OnUpdating="SqlDataSource1_Updating" OnInserted="SqlDataSource1_Inserted" OnInserting="SqlDataSource1_Inserting">
        <DeleteParameters>
            <asp:Parameter Name="product_rules_id" Type="Int32" />
            <asp:Parameter Name="original_product_rules_id" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Direction="ReturnValue" Name="RETURN_VALUE" Type="Int32" />
            <asp:Parameter Name="product_rules_id" Type="Int32" />
            <asp:Parameter Name="original_product_rules_id" Type="Int32" />
            <asp:Parameter Name="supplier_im_id" Type="String" DefaultValue="" />
            <asp:Parameter Name="product_id" Type="String" />
            <asp:Parameter Name="company_id" Type="Int32" />
            <asp:Parameter Name="effective_date" Type="DateTime" />
            <asp:Parameter Name="base_cost" Type="Double" />
            <asp:Parameter Name="capability_support_cost" Type="Double" />
            <asp:Parameter Name="service_cost" Type="Double" />
            <asp:Parameter Name="cc_im" Type="String" />
            <asp:Parameter Name="cc_pct" Type="Double" />
            <asp:Parameter Name="qh_im" Type="String" />
            <asp:Parameter Name="qh_margin" Type="Double" />
            <asp:Parameter Name="qh_pct" Type="Double" />
            <asp:Parameter Name="active" Type="Boolean" />
            <asp:Parameter Name="unit_type" Type="String" />
            <asp:SessionParameter ConvertEmptyStringToNull="False" DefaultValue="" Name="LastModBy"
                SessionField="UserID" Size="15" Type="String" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="supplier_im_id" Type="String" />
            <asp:Parameter Name="product_id" Type="String" />
            <asp:Parameter Name="company_id" Type="Int32" />
            <asp:Parameter Name="effective_date" Type="DateTime" />
            <asp:Parameter Name="base_cost" Type="Double" />
            <asp:Parameter Name="capability_support_cost" Type="Double" />
            <asp:Parameter Name="service_cost" Type="Double" />
            <asp:Parameter Name="cc_im" Type="String" />
            <asp:Parameter Name="cc_pct" Type="Double" />
            <asp:Parameter Name="qh_im" Type="String" />
            <asp:Parameter Name="qh_margin" Type="Double" />
            <asp:Parameter Name="qh_pct" Type="Double" />
            <asp:Parameter Name="active" Type="Boolean" />
            <asp:Parameter Name="unit_type" Type="String" />
            <asp:SessionParameter Name="LastModBy" SessionField="UserID" Type="String" />
        </InsertParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="txtDate" Name="dtEffectiveDate" PropertyName="Text"
                Type="DateTime" />
        </SelectParameters>
    </asp:SqlDataSource>
 
 
 
In code: 
    string pagename = "frmRule";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                //fill header, body and footer labels
                GetPageContent(pagename, lblHeader, lblBody, lblFooter);
                txtDate.Text = System.DateTime.Now.ToShortDateString();
                Session["UserID"] = "test userid";
                
            }
            catch (Exception exp)
            {
                HandleError(exp, pagename, lblResult);
            }
        }
}

Open in new window

0
 

Author Comment

by:KBSLPDev
ID: 20404433
Found that if I changed one of the parameter's value in the grid's UpdateRow method to be what I wanted rather than the Update parameter value definition of the sqldatasource, the problem was corrected.

    protected void UltraWebGrid1_UpdateRow(object sender, RowEventArgs e)
    {
        //set the last mod by to be the user id
        e.Row.Cells[15].Value = Session["UserID"].ToString();
    }

Thanks!
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 20592633
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question