如何在业务逻辑中使用输出参数传递给sp

如何在业务逻辑中使用输出参数传递给sp

本文介绍了如何在业务逻辑中使用输出参数传递给sp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用输入和输出参数编写了一个sp,如何在c#

i have written a sp with input and out put parameter ,how can i call that sp from my business logic in c#

推荐答案

SqlConnection sqlConnection1 = new SqlConnection("Your Connection String");
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;

cmd.CommandText = "StoredProcedureName";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = sqlConnection1;

sqlConnection1.Open();

reader = cmd.ExecuteReader();
// Data is accessible through the DataReader object here.

sqlConnection1.Close();



请参阅:

[]

[]



-KR


Refer this:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET[^]
How to: Execute a Stored Procedure that Returns Rows[^]

-KR


using (SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=test;Integrated Security=True"))
using (SqlCommand cmd = new SqlCommand("SPname", con))
{
    cmd.CommandType = CommandType.StoredProcedure;

    cmd.Parameters.Add(new SqlParameter("@opparam1", SqlDbType.Int));
    cmd.Parameters["@opparam1"].Direction = ParameterDirection.Output;

    con.Open();
    cmd.ExecuteNonQuery();
    int outputvalue = (int)cmd.Parameters["@opparam1"].Value;
    con.Close();
}



这篇关于如何在业务逻辑中使用输出参数传递给sp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 19:33