سلام بر تمامی برنامه نویسان #C 😉 در این مطلب کد SqlConnection: گرفتن مقدار بازگشتی از یک Stored Procedure در سی شارپ را آماده کردم. انشاالله که این کد سی شارپ براتون مفید باشد.
کد SqlConnection: گرفتن مقدار بازگشتی از یک Stored Procedure در سی شارپ :
/*
CREATE PROCEDURE Person.GetContacts
@RowCount int OUTPUT
AS
SET NOCOUNT ON
SELECT * FROM Person.Contact
SET @RowCount = @@ROWCOUNT
RETURN @RowCount
*/
using System;
using System.Data;
using System.Data.SqlClient;
class Program
{
static void Main(string[] args)
{
string sqlConnectString = "Data Source=(local);" +
"Integrated security=SSPI;Initial Catalog=AdventureWorks;";
using (SqlConnection connection = new SqlConnection(sqlConnectString))
{
SqlCommand command =new SqlCommand("Person.GetContacts", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@RowCount", SqlDbType.Int).Direction = ParameterDirection.Output;
SqlParameter retParam = command.Parameters.Add("@RetVal", SqlDbType.Int);
retParam.Direction = ParameterDirection.ReturnValue;
CREATE PROCEDURE Person.GetContacts
@RowCount int OUTPUT
AS
SET NOCOUNT ON
SELECT * FROM Person.Contact
SET @RowCount = @@ROWCOUNT
RETURN @RowCount
*/
using System;
using System.Data;
using System.Data.SqlClient;
class Program
{
static void Main(string[] args)
{
string sqlConnectString = "Data Source=(local);" +
"Integrated security=SSPI;Initial Catalog=AdventureWorks;";
using (SqlConnection connection = new SqlConnection(sqlConnectString))
{
SqlCommand command =new SqlCommand("Person.GetContacts", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@RowCount", SqlDbType.Int).Direction = ParameterDirection.Output;
SqlParameter retParam = command.Parameters.Add("@RetVal", SqlDbType.Int);
retParam.Direction = ParameterDirection.ReturnValue;