将aspnet_users UserName值添加到我自己的表中

时间:2009-03-22 17:55:42

标签: asp.net

我想将aspnet_users中的UserName插入到我自己的名为Members的表中。我的sqldatasource如下所示。在InsertParameters的最后,我添加了ProfileParameter,但它不起作用。只是为了获得值,我在insertcommand中硬编码了'testhere'值。我的SQLDatasource如下所示。

请帮助!!!

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    OnInserted= "on_inserted"
    OnUpdated = "on_updated"

        ConnectionString="<%$ ConnectionStrings:test1ConnectionString %>" 
        DeleteCommand="DELETE FROM [member] WHERE [id] = @id" 
        InsertCommand="INSERT INTO [member] ([firstname], [lastname],[username]) VALUES (@firstname, @lastname,'testhere');
                            set @id = @@identity"  
        SelectCommand="SELECT * FROM [member] WHERE ([id] = @id)" 

        UpdateCommand="UPDATE [member] SET [firstname] = @firstname, [lastname] = @lastname WHERE [id] = @id" 
        onselecting="SqlDataSource1_Selecting">
        <SelectParameters>
            <asp:QueryStringParameter Name="id" QueryStringField="id" Type="Int32" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="id" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="firstname" Type="String" />
            <asp:Parameter Name="lastname" Type="String" />
            <asp:Parameter Name="id" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
         <asp:Parameter Name="id" Type=Int32 Direction=Output />
            <asp:Parameter Name="firstname" Type="String" />
            <asp:Parameter Name="lastname" Type="String" />
            <asp:ProfileParameter Name="username" Type=String /> 
        </InsertParameters>
    </asp:SqlDataSource>

1 个答案:

答案 0 :(得分:0)

好的......作为一个简单的:

  • 尝试将InsertParameter(用户名)更改为asp:Parameter。
  • 添加ID为username
  • 的asp:HiddenField控件
  • onpageload,将用户名hiddenfield的值设置为Page.User.Identity.Name

魔术!