|
|
 |
| 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.
|
 |

February 25th, 2009, 02:46 PM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 23
Thanks: 10
Thanked 0 Times in 0 Posts
|
|
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. 
|

February 27th, 2009, 05:28 AM
|
 |
Wrox Author
Points: 33,554, Level: 80 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,228
Thanks: 7
Thanked 203 Times in 201 Posts
|
|
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
|

March 3rd, 2009, 07:56 AM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 23
Thanks: 10
Thanked 0 Times in 0 Posts
|
|
Oops, sorry about the mile long code! Didn't realise! - I think the pending deadline on submission of this project is getting to me!
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |