好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

SqlDataSource上的存储过程不能使用单引号C#asp.net在SelectCommand中

我现在遇到麻烦,关于如何让我的存储过程在aspx页面上的SqlDataSource中工作.

这是我的标记:

<asp:SqlDataSource ID="SqlDataSourceGrantInfo" runat="server" 
     ConnectionString="<%# _connection.strConnectionString %>"
     SelectCommand='<%# "EXEC dbo._GetCurrentSession " + Eval("Film_strCode") + " " %>' />

上面的代码工作正常,但没有单引号.但是,当我试图单引号时,它不起作用.标签上会出错.

看到这个标记:

<asp:SqlDataSource ID="SqlDataSourceGrantInfo" runat="server" 
     ConnectionString="<%# _connection.strConnectionString %>"
     SelectCommand='<%# "EXEC dbo._GetCurrentSession 'some_value_here' " %>' />

请帮助我知道为什么单引号的存储过程在aspx页面上不起作用?我需要用单引号制作我的代码,但它不起作用.

<asp:SqlDataSource ID="SqlDataSourceGrantInfo" runat="server" 
     ConnectionString="<%# _connection.strConnectionString %>"
     SelectCommand='<%# "EXEC dbo._GetCurrentSession '" + Eval("Film_strCode") + "'" %>' />

有什么方法可以使它工作吗?请帮我.

如果要使用SqlDataSource中的存储过程,则应使用此方法 – 将命令类型定义为StoredProcedure,并正确设置参数:

<asp:SqlDataSource ID="SqlDataSourceGrantInfo" runat="server" 
     ConnectionString="<%# _connection.strConnectionString %>"
     SelectCommand="dbo._GetCurrentSession"
     SelectCommandType="StoredProcedure">
    <SelectParameters>
        <asp:Parameter Name="SessionValue" Type="Int32" DefaultValue="0" />
    </SelectParameters>
</asp:SqlDataSource>

查看更多关于SqlDataSource上的存储过程不能使用单引号C#asp.net在SelectCommand中的详细内容...

  阅读:54次