SqlDataSource Parameterized Stored Procedure Problem!!

K

Kel

I am currently trying to pass the SqlDataSource below a paramter set in
the code-behind (C#) My stored procedure takes one parameter @AID
varchar(25).

<asp:SqlDataSource ID="ListEmpSource" Runat="server"
SelectCommand="dbo.usp_ListEmps"

ConnectionString="Server=(local);Database=Test;Trusted_Connection=yes"
SelectCommandType="StoredProcedure" >

<SelectParameters>
<asp:parameter Name="AID" Direction="input" Type="string"
DefaultValue="username" />
</SelectParameters>

</asp:SqlDataSource>

Then in the codebehind I try to do this (one of many solutions I've
tried)

string strUserName = User.Identity.Name;

ListEmpSource.Selecting += new
SqlDataSourceSelectingEventHandler(ListEmpSource_Selecting);

//Event Handler:
public void ListEmpSource_Selecting(object sender,
SqlDataSourceSelectingEventArgs e)
{
e.Command.Parameters["@AID"].Value = strUserName;
}

Thanks in advance...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top