Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 11th, 2007, 11:26 AM
Authorized User
 
Join Date: Mar 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pass UserName to Database

Hello, I didn't get much response on my first posting, so I'm trying again (hopefully being a little clearer)

I want to be able to pass the logged in name from the website to the database for Selecting.

I have spent days and days on this now and I just do not know where else to turn. I have been through topic 40908 MANY times. For some reason it will not pass the parameter to the database.
Any help would be extremely appreciated.

<script runat="server">

protected void MyActivities_Selecting(Object sender, System.Web.UI.WebControls.SqlDataSourceSelectingEv entArgs e)

            {
                e.Command.Parameters["@UserName"].Value = Membership.GetUser().UserName;
        }

</script>


<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
</head>


<body>

<form id="form1" runat="server">
<asp:LoginName runat="server" id="LoginName1" />
<asp:LoginStatus runat="server" id="LoginStatus1" />
<asp:GridView runat="server" id="GridView1" AutoGenerateColumns="False" DataSourceID="MyActivities">
    <Columns>
        <asp:boundfield DataField="UserName" SortExpression="UserName" HeaderText="UserName">
        </asp:boundfield>
    </Columns>
</asp:GridView>
<asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:connectionName %>" ProviderName="<%$ ConnectionStrings:connectionName.ProviderName%>" SelectCommand="SELECT [UserName] FROM [TABLE] WHERE ([UserName] = @UserName)">
    <SelectParameters>
        <asp:Parameter Type="Object" DefaultValue="test" Name="UserName" />
    </SelectParameters>
</asp:SqlDataSource>

</form>

</body>

</html>

Thanks Lee.






Similar Threads
Thread Thread Starter Forum Replies Last Post
username and password abhi_loveu2002 ASP.NET 2.0 Basics 1 December 14th, 2006 05:25 AM
Username is not accepted in to the database madhusrp ASP.NET 1.0 and 1.1 Professional 3 March 19th, 2006 12:19 AM
Username Changes Ben Horne Forum and Wrox.com Feedback 2 March 12th, 2004 12:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.