Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 31st, 2011, 07:47 PM
FOD FOD is offline
Authorized User
 
Join Date: May 2011
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing UserId to a stored procedure or query FOD BOOK: Beginning ASP.NET 4 : in C# and VB 8 June 1st, 2011 12:13 PM
Passing Paramter-Stored Procedure ms1234 Crystal Reports 2 May 22nd, 2007 11:34 AM
Passing an "IN" clause to a stored procedure atcs2152 SQL Server 2000 5 February 7th, 2006 10:55 PM
Passing a parameter value to Stored Procedure mcinar SQL Server 2000 9 October 3rd, 2004 09:42 PM
passing stored procedure shoakat SQL Server 2000 1 July 15th, 2004 09:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.