C# 用c中的分号版本执行StoredProcess
如何在c中的slqdatasource中执行具有版本控制的存储过程? 我有一个很大的数据库,其中有一个由版本控制控制的存储过程,但是我在用这个存储过程执行SQL数据源时遇到了一个问题。 以下是我的代码示例:C# 用c中的分号版本执行StoredProcess,c#,sql-server,C#,Sql Server,如何在c中的slqdatasource中执行具有版本控制的存储过程? 我有一个很大的数据库,其中有一个由版本控制控制的存储过程,但是我在用这个存储过程执行SQL数据源时遇到了一个问题。 以下是我的代码示例: <asp:SqlDataSource ID="SqlDataSource9" runat="server" ConnectionString="<%$ ConnectionStrings:TestConnectionString %>"
<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>
有了这段代码,我得到了错误的无效对象名。存储过程不是这样执行的。您可以这样尝试:
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>
谢谢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>
在我的代码中。
感谢您的支持。对于存储过程,您需要使用EXEC[Treasury]。[STP_T00042005];3 exec的语法是什么?我的storedprocedure有一些参数,我可以在sqldatasourceselecting事件中填充这些参数。您不能调用SELECT之类的存储过程。。。来自proc_name。您需要使用EXEC proc_name