Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object reference not set to an instance of an object.

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
GB
When a user logins to my application I am creating a session variable called 'User'. The user logins with their DXNumber)

Code:
Session("User") = txtDXNumber.Text

I am then using this session as part of a datasource as below:

Code:
<asp:sqldatasource runat="server" id="GetUserID" 
    ConnectionString="<%$ ConnectionStrings:FileawaySQLConnectionString %>" 
    SelectCommand="SELECT [BusinessID] FROM [Businesses] WHERE ([DXNumber] = @DXNumber)">
    <SelectParameters>
        <asp:SessionParameter Name="DXNumber" SessionField="User" Type="String" />
    </SelectParameters>
</asp:sqldatasource>

When I get the corresponding BusinessID, I populate a hidden label with the value

Code:
Dim dvUserID As Data.DataView = GetUserID.Select(DataSourceSelectArguments.Empty)
        Me.lblUserID.Text = dvUserID.ToTable.Rows(0)("BusinessID")

Then I link my data to the value in the label.

I am assuming that when the session expires then the value in the lblUserID is NULL which is giving me the Object reference error.

I obviously dont want to leave the session open indefinately but is there any code I can add that checks if its NULL then requery the value again or something?

 
This is only one of the many reasons that I don't like the DataSourceControls. If you write the code yourself, you can do a check for the Session var first, then run your code accordingly. You can see if the control has some sort of way to check, but I doubt it. My suggestion, write the data access code yourself.
 
what do you mean write the code? write the code to create the session? i am not sure where I would begin. any suggestions?

thanks
 
No, what I mean is to write the data access code yourself, and NOT use the data source controls.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top