0

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 

1 Answer 1

1

You need to pass the parameters value instead of adding the parameter in the SQLDataSource. Since you have already added the parameter in the SelectParameters Collection, 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..

string name = ModeratorUsefulFunctions.GetMessageUsersName(g);

SqlDataSource1.SelectParameters["name"].DefaultValue = name;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks it worked... The 'n' should be 'N'..this corrects the situation..The answer was right..thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.