p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > ASP.NET and ASP > ASP.NET 3.5 > Visual Web Developer 2008
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Visual Web Developer 2008 Discuss creating ASP.NET 3.5 sites with Microsoft's Visual Web Developer 2008. If your question is more specific to a piece of code than the Visual tool, see the ASP.NET 3.5 forums instead. If your question is specific to the "Express Edition" be sure to state that in your post.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Web Developer 2008 section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 25th, 2009, 02:46 PM
Authorized User
Points: 105, Level: 2
Points: 105, Level: 2 Points: 105, Level: 2 Points: 105, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2009
Posts: 23
Thanks: 10
Thanked 0 Times in 0 Posts
Default Query based on UserName when UserId is the Primary key

I am developing a system in Visual Web Developer 2008 Express Edition. I have been able to get a sign-in feature working, and have been able to pull out user specific data when the user is logged in.

The following is the code I am using to do this:
Code:
<asp:SqlDataSourceID="SqlDataSource1"runat="server"
ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString1 %>"SelectCommand="SELECT vw_aspnet_Users.UserName, aspnet_Membership.Email, UserAddresses.BillingAddress, UserAddresses.BillingCity, UserAddresses.BillingState, UserAddresses.BillingZip, UserAddresses.ShippingAddress, UserAddresses.ShippingCity, UserAddresses.ShippingState, UserAddresses.ShippingZip FROM vw_aspnet_Users INNER JOIN aspnet_Membership ON vw_aspnet_Users.UserId = aspnet_Membership.UserId INNER JOIN UserAddresses ON aspnet_Membership.UserId = UserAddresses.UserId WHERE (vw_aspnet_Users.UserName LIKE '%' + @UserName + '%')">
<SelectParameters>
<asp:ParameterDefaultValue=""Name="UserName"Type="String"/>
</SelectParameters>
</asp:SqlDataSource>
This is the code behind
Code:
ProtectedSub SqlDataSource1_Selecting(ByVal sender AsObject, _
ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) _
Handles SqlDataSource1.Selecting
Dim userName AsString = Context.User.Identity.Name
e.Command.Parameters("@UserName").Value = userName
EndSub
I am now getting to the stage where I need to be able to allow my user to edit their profile information. I can display the information of all my users on the home page, and at this location I can edit and update the database. Obviously this is useless (except that I know it can be done!) I know that this is only possible when I include the UserId in the gridview - ie that I can only choose the select/update options when I include a promary key field.

When I try to create the same table within my signin area it crashes because it is trying to execute the WHERE clause based on UserName, and I think it is taking the UserName from the LoginName label.

Logically I think I need to somewhere tell it to associate the UserName with the specific UserId primary key.

If anyone understands what I am trying to do and can give me some pointers, it'd be greatly appreciated.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old February 27th, 2009, 05:28 AM
Imar's Avatar
Wrox Author
Points: 33,554, Level: 80
Points: 33,554, Level: 80 Points: 33,554, Level: 80 Points: 33,554, Level: 80
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,228
Thanks: 7
Thanked 203 Times in 201 Posts
Default

Code:
 
it crashes because it is trying to execute the WHERE clause based on UserName, and I think it is taking the UserName from the LoginName label
That's not in the code you posted, so it's a bit difficult to say something useful here.

Why does it use that label? Why not simply get the user ID from the current Membership user?

Also, when you post code here, can you please add a few line breaks here and there? The page is now about a meter wide.... ;-)

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004

Did this post help you? Click the button to show your appreciation!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old March 3rd, 2009, 07:56 AM
Authorized User
Points: 105, Level: 2
Points: 105, Level: 2 Points: 105, Level: 2 Points: 105, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2009
Posts: 23
Thanks: 10
Thanked 0 Times in 0 Posts
Default

Oops, sorry about the mile long code! Didn't realise! - I think the pending deadline on submission of this project is getting to me!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Get my Anonymous username or userID Maxxim ASP.NET 2.0 Professional 7 October 21st, 2007 09:17 AM
Foreign key not updating with Primary key xavier1945 BOOK: Access 2003 VBA Programmer's Reference 2 July 4th, 2007 10:48 PM
Return Primary Key of Last Append Query mselkregg Access 1 November 16th, 2006 11:36 AM
Chapter 10 - username as a primary key sbillingsley BOOK: Professional ASP.NET 2.0 Security, Membership, and Role Management ISBN: 978-0-7645-9698-8 1 April 6th, 2006 01:47 PM
Primary Key Prob with SQL SP with Primary Key bekim ASP.NET 1.1 0 September 3rd, 2004 11:51 PM



All times are GMT -4. The time now is 12:28 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc