I have a webform called UserProfile.aspx. After user logged-in, they can view their particulars at UserProfile. I used SqlDatasource and was binde with DetailsView.
In the detailsview, it retrieved data from 2 table; aspnet_Membership and Details table respectively.
Following is the code which I get the current logged-in user(inside UserProfile.aspx.cs):
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
MembershipUser currentUser = Membership.GetUser();
Guid currentUserId = (Guid)currentUser.ProviderUserKey;
DbParameter param = e.Command.CreateParameter();
param.ParameterName = "@UserId";
param.Value = currentUserId;
and here is my SQL SELECT query:
SELECT Details.CustName, Details.UserId, Details.CustNum, Details.CustRole, Details.CustStatus, Details.PName, Details.PEmail, Details.PRole, Details.WedDate, aspnet_Membership.Password, aspnet_Membership.Email FROM Details INNER JOIN aspnet_Membership ON Details.UserId = aspnet_Membership.UserId WHERE (Details.UserId = @UserId)
and this line from the select statement seem to have problem:
WHERE (Details.UserId = @UserId)
they could not detect whose is the currentUser and when i execute the query in the query builder, a dialog-box pop up and prompt to enter value for its parameter. and it was stated that "@UserId" was null which I have no idea why is it so when I had already passed the value.
Please give me suggestions and solutions on how to solve this as I already at my wits, I had researched about this the whole day but it was no luck..