SqlDataSource上的存储过程不能使用单引号C#asp.net在SelectComm
发布时间:2020-12-16 10:00:09 所属栏目:百科 来源:网络整理
导读:我现在遇到麻烦,关于如何让我的存储过程在aspx页面上的SqlDataSource中工作. 这是我的标记: asp:SqlDataSource ID="SqlDataSourceGrantInfo" runat="server" ConnectionString="%# _connection.strConnectionString %" SelectCommand='%# "EXEC dbo._GetCur
我现在遇到麻烦,关于如何让我的存储过程在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> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |