locked
Problem with Select Statment WHERE UserName = (user log in name?) RRS feed

  • Question

  •  

    I am using Visual Studio Web Developer 2005 Express and SQL Server 2005

    Using the log in controls I have created a log in page, using the asp.net web site administration tool I added a few test usernames and passwords, and so far everyhing works fine.

     

    My problem is that I have a table with usernames and descriptions of events and I want the user to just see the events relevant to that user.

    username date description

    client1 7/1/2007 phone call to client

    client2 7/1/2007 phone call

    client1 7/2/2007 research

    client2 7/2/2007 prepared letter

     

    I placed a gridview on the page. On the Gridview tasks I configured the database connection and tried to configure the select statement. If I use

     

    SELECT [UserName], [Date], [Description] FROM [Slips]

     

    then the user sees all the entires, so I am trying to add a proper WHERE portion. If I use the Select Configuration tool where

    Column is UserName

    Operator is = and

    Source is Session; and I put UserName in the Session Field of the Parameter properties it creates a Select Statement that returns no results. I am sure it is because I am not properly testing it agaist the username the user is logged in with. I don't know if Session is the right source or what the username variable is.  Any help would be apprecitated.

    Thursday, August 2, 2007 7:39 PM

Answers

  • I am using SQLServer.  WHERE UserName = @UserName is what the Select statement configuration came up with, but for some reason @UserName did not seem to have the users login name in it. 

    When configuring the select statement it asks for the parameter type and I was guessing that the type was the Session variable associated with the web browser.

    I realize now I should have posted this in the asp.net forms for visual studio web developer edition. 

    I looked there and found this http://forums.asp.net/p/1132531/1801587.aspx#1801587 post that helped me get it to work.

    Thank you for the help though!
    Friday, August 3, 2007 9:27 PM

All replies

  • If you're using SQLServer Add the where clause below and you can refer to UserName in the paramters collection:
    WHERE UserName = @UserName

    I'm not clear on what 'Session' is?
    Friday, August 3, 2007 4:13 AM
  • I am using SQLServer.  WHERE UserName = @UserName is what the Select statement configuration came up with, but for some reason @UserName did not seem to have the users login name in it. 

    When configuring the select statement it asks for the parameter type and I was guessing that the type was the Session variable associated with the web browser.

    I realize now I should have posted this in the asp.net forms for visual studio web developer edition. 

    I looked there and found this http://forums.asp.net/p/1132531/1801587.aspx#1801587 post that helped me get it to work.

    Thank you for the help though!
    Friday, August 3, 2007 9:27 PM