在c#中执行带有版本分号的存储过程
本文关键字:存储过程 版本 执行 行带 | 更新日期: 2023-09-27 18:16:48
如何在c#的slqdatasource中执行带有版本控制的存储过程?我有一个大型数据库,其中包含一个使用版本控制控制的存储过程,但是我在使用该存储过程执行SQL数据源时遇到了一个问题。下面是我的代码示例:
<asp:SqlDataSource ID="SqlDataSource9" runat="server"
ConnectionString="<%$ ConnectionStrings:TestConnectionString %>"
ProviderName="<%$ ConnectionStrings:TestConnectionString.ProviderName %>"
SelectCommand="SELECT [pyprmtflID], [pt_desc] FROM [Treasury].[STP_T00042005];3">
</asp:SqlDataSource>
使用这段代码,我得到错误无效的对象名称。
谢谢Rahul我找到了。你的代码是c#代码后面,对于在运行时中使用sqldatasource,我使用:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:TestConnectionString %>"
SelectCommand="[Treasury].[STP_T00042005];15" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="F_UserId" Type="Int32" DefaultValue="94" />
</SelectParameters>
</asp:SqlDataSource>
我的代码中的。谢谢lad2025。
存储过程不是这样执行的。您可以这样尝试:
using (var conn = new SqlConnection(connectionString))
using (var command = new SqlCommand("[Treasury].[STP_T00042005]", conn))
{
CommandType = CommandType.StoredProcedure })
{
conn.Open();
command.ExecuteNonQuery();
conn.Close();
}
正如lad2015所说,您需要使用EXEC命令执行存储过程。试试这样
<asp:SqlDataSource ID="SqlDataSource9" runat="server"
ConnectionString="<%$ ConnectionStrings:TestConnectionString %>"
ProviderName="<%$ ConnectionStrings:TestConnectionString.ProviderName %>"
SelectCommand="[Treasury].[STP_T00042005];" SelectCommandType="StoredProcedure">
</asp:SqlDataSource>