Currently logged in user - selectparameter declaration

Posted on 2005-05-15
Last Modified: 2012-05-05
I am trying to build an sqldatasource using a parameter which I want set to the currently logged in user's username. Any idea how to declare the parameter in the <SelectParameter> tag? ie, my selectstatement is select *** from *** where username = @username... Maybe even if I could declare it in the codebehind using VB using the Membership methods. I am using .net 2.0...
Question by:alfer
    LVL 7

    Accepted Solution

    asp classic:
    Function GetUserName()
          Dim domain_user
          if Request.ServerVariables("LOGON_USER") = "" then
                domain_user = split( "Blah\Admin Must Disable Anonymous Access", "\" )
                domain_user = split(Request.ServerVariables("LOGON_USER"),"\")
          end if
          GetUserName = domain_user(1)
    End Function

    .net?  really should take the time to learn that.
    LVL 2

    Assisted Solution

    "SELECT * FROM tblUsers WHERE user_Name = '" + strUserName + "'"

    Where tblUsers is the users' table,
    Where user_Name is the username field in the users' table,
    Where strUserName is the variable holding the username.

    >Function GetUserName()
    >     Dim domain_user
    >     if Request.ServerVariables("LOGON_USER") = "" then
    >          domain_user = split( "Blah\Admin Must Disable Anonymous Access", "\" )
    >     else
    >          domain_user = split(Request.ServerVariables("LOGON_USER"),"\")
    >     end if
    >     GetUserName = domain_user(1)
    >End Function

    then your connection.source would be :

    "SELECT * FROM tblUsers WHERE user_Name = '" + GetUserName() + "'"

    LVL 22

    Expert Comment

    No comment has been added to this question in more than 21 days, so it is now classified as abandoned.  I will make a recommendation to the moderators on its resolution in a week or two.  I appreciate any comments that would help me to make a recommendation.

    Unless it is clear to me that the question has been answered I will recommend delete without refund of points.  It is possible that a Grade less than A will be given if no expert makes a case for an A grade.  It is assumed that any participant not responding to this request is no longer interested in its final disposition.

    If the asker does not know how to close the question, the options are here:

    EE Cleanup Volunteer
    LVL 22

    Expert Comment

    No comment has been added to this question in more than 21 days, so it is now classified as abandoned.  I will leave the following recommendation for this question in the Cleanup topic area:
    Split - Hecatonchires, craigofcapetown

    Any objections should be posted here in the next 4 days.  After that time, the question will be closed.

    EE Cleanup Volunteer

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
    This demonstration started out as a follow up to some recently posted questions on the subject of logging in: and…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    730 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now