I have an sqldatasource that takes a stored procedure with a parameter..But that the stored procedure doesnt get executed…
Am I passing the parameter successfully?
SQLDataSource:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CP_AllQuestionsAnswered %>"
SelectCommand="GetMessagesTitles" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="Name" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
The pageLoad code behind:
string name = ModeratorUsefulFunctions.GetMessageUsersName(g);
SqlDataSource1.SelectParameters.Add("@Name", name);
The stored procedure:
ALTER PROCEDURE dbo.GetMessagesTitles
@Name nvarchar(50)
AS
SELECT MessageTitle, MessageID
FROM Messages
WHERE MessageTo=@Name
You need to pass the parameters value instead of adding the parameter in the SQLDataSource. Since you have already added the parameter in the
SelectParametersCollection, you only need to pass the value. The way you are doing, it adds another Select parameter, that’s the problem.It should be like..