开发者

Sending variables to sqldatasource

开发者 https://www.devze.com 2023-03-20 23:12 出处:网络
I have an sqldatasource that takes a stored procedure with a parameter..But that the stored procedure doesnt get executed...

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" Select开发者_如何学GoCommandType="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 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;
0

精彩评论

暂无评论...
验证码 换一张
取 消