Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > Visual Web Developer 2008
|
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 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 February 25th, 2009, 02:46 PM
Authorized User
 
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.
 
Old February 27th, 2009, 05:28 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old March 3rd, 2009, 07:56 AM
Authorized User
 
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!





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 08:17 AM
Foreign key not updating with Primary key xavier1945 BOOK: Access 2003 VBA Programmer's Reference 2 July 4th, 2007 09:48 PM
Return Primary Key of Last Append Query mselkregg Access 1 November 16th, 2006 11:36 AM





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