Hi larsenal,
It's almost the same with an AccessDataSource, except that you don't refer to the parameters by name, but by their index. Here's q quick example using a GridView:
Code:
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/Database1.mdb" OnSelecting="AccessDataSource1_Selecting"
SelectCommand="SELECT * FROM [Test] WHERE ([UserName] = ?)">
<SelectParameters>
<asp:Parameter Name="UserName" Type="String" />
</SelectParameters>
</asp:AccessDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true"
DataKeyNames="ID" DataSourceID="AccessDataSource1" />
And then in the Code Behind you need this:
Code:
protected void AccessDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
e.Command.Parameters[0].Value = Context.User.Identity.Name;
}
This assigns the user name to the first (and only) parameter defined in the query.
Hope this helps,
Imar
---------------------------------------------------------------------------------------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on
Twitter.
Everyone is unique, except for me.
Author of
Beginning ASP.NET 4 : in C# and VB,
Beginning ASP.NET 3.5 : in C# and VB, and
ASP.NET 2.0 Instant Results.
While typing this post, I was listening to: Kitty Litter by Placebo (From the album: Battle for the Sun) What's This?