views:

474

answers:

2

I am using VisualWebDeveloperExpress2008 with Access as the membership provider.

I have some cases where I want users to edit their own data. This would involve a query where the UserId should equal the UserID of the user who is using the site.

I am expecting to use WHERE UserId = ?, but I have not found out where to direct "?".

The IDE gives several choices, but I am uncertain which to choose. This, while it looks promising does not work:

<SelectParameters>
    <asp:ProfileParameter Name="UserID" PropertyName="UserId" Type="Int32" />
</SelectParameters>

What is best to use for the Select Parameter?

+1  A: 

User.Identity.Name should provide you the username of the logged in user.

Now, to get the UserID you will need to check it in the database using the username. Or you can make it so that the select statement uses the username instead.

Farinha
OK, if I have the UserName, that would be second best to getting the UserID directly, as I can JOIN to it...I am assuming you mean, "<asp:ProfileParameter Name="UserName" PropertyName="User.Identity.Name" Type="Int32" />"This leads to the error: DataBinding: 'ProfileCommon' does not contain a property with the name 'User'. Maybe you mean something else?
Degan
A: 

Try using

<SelectParameters>
    <asp:SessionParameter Name="UserName" SessionField="CurrentUser" Type="String" />
</SelectParameters>

On the Page_Load insert the following...

Session["CurrentUser"] = User.Identity.Name;

This should work for you.

jinsungy
better to put that in the session start event handler
SillyMonkey
@SillyMonkey, very good point. +1
jinsungy
This works for me. Now I need to research how to put this in the "session start event handler".
Degan