PDA

View Full Version : Get data based on UserName (ASP)


Wardie
10-08-2007, 12:20 PM
Hey guys, first post!

I'm new to ASP.net and i'm struggling with a problem, any help will be appreciated.

All the information i've found for doing this relies on the UserName being the PK, this isn't the case for the table i'm using. I am however using the default membership provider tables and controls.

I basically just need a way of showing ONLY the data for the user that is logged in.

The SQL query is in the Dataset as:

SELECT ID, WorkCode, WorkDate, Hours
FROM Hours

WHERE UserName = (@UserName)

Really can't find how to do this :(

Here's a overview of the tables involved:

tblCodes
CodeID (PK)
CodeName
CodeDescription
CodeType
CodeOwner

tblHours
ID (PK)
WorkCode
WorkDate
Hours
UserName

aspnet_Users
ApplicationID
UserId (PK)
UserName
LoweredUserName
MobileAlias
IsAnonymous
LastActivityDate

I know i've asked a lot of questions on here lately and thanks for helping guys, really struggle to find decent information for this though.

Thanks for any help.

jleone
10-08-2007, 06:41 PM
Well, hopefully the username column in your Hours table is a foreign key to the username column in your Users table. If so, try the following SQL statement. Use a "join" and go directly through the Users table to use the primary key value. Good luck.

SELECT h.ID, h.WorkCode, h.WorkDate, h.Hours
FROM Hours h join Users u on h.username = u.username
WHERE u.UserName = (@UserName)