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.
