Passing UserId to a stored procedure or query
I was asked to repost this question to provide more people the opportunity to see it. I ended up figuring out a way to make it work using the code I provide underneath. Feel free to add better suggestions as I really don't know what I'm doing.
Original Post
I have a table where one of my fields is the UserId (uniqueidentifier) assigned by the login system that is included with ASP.net. I am trying to write a query where when I log in I can go to a page with a listview control that SELECTS all of the table records WHERE the OwnerId within the table is equal to the logged in UserId.
I've tried setting a variable in the code behind and passing it as a parameter along with numerous other options such as trying to pass it to a stored procedure, none of which have worked.
To be honest I'm at a loss and would appreciate any help you can provide I'm sure the answer is probably simple and I'm just not seeing it.
Solution
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Using TMSEntities As New TMSEntities()
Dim userId = Membership.GetUser().ProviderUserKey()
Dim myStuff = From stuff In TMSEntities.stuff
Where stuff.OwnerId = userId
Select stuff.stuffname, stuff.OwnerId
ListView1.DataSource = myStuff
ListView1.DataBind()
End Using
End Sub
Thanks,
FOD
|