2

In this way, I retrieve data using the stored procedure:

var returnParameter = new SqlParameter("@RV", SqlDbType.Int) { Direction = ParameterDirection.Output };
var xmlParameter = new SqlParameter("@XML", XML) { DbType = DbType.Xml };
var familySentParameter = new SqlParameter("@FamilySent", SqlDbType.Int) { Direction = ParameterDirection.Output };

//var resultParameter = new SqlParameter("Result", SqlDbType.Text) { Direction = ParameterDirection.ReturnValue };

var sql = "exec @RV = uspConsumeSomething @XML, @FamilySent OUT";

var result = myContext.Database.ExecuteSqlCommand(sql, returnParameter, xmlParameter, familySentParameter);

RV = (int)returnParameter.Value;

Below the fragment of the stored procedure (termination of the procedure):

BEGIN CATCH
    SELECT ERROR_MESSAGE();
    IF @@TRANCOUNT > 0 ROLLBACK TRAN ENROLL;

    SELECT * FROM @tblResult;
    RETURN -400
END CATCH

SELECT Result FROM @tblResult;

RETURN 0 --ALL OK
END

How to obtain in C# data obtained from:

  • SELECT * FROM @tblResult;
  • SELECT Result FROM @tblResult;

They are not needed for the operation of the procedure but contain information about the type of error that arises in the stored procedure.

The use of Return in a stored procedure is supported by @RV

EDIT:

I'm trying a different approach but I still do not know how to get the values from SELECT here

DbConnection connection = myContext.Database.GetDbConnection();

using (DbCommand cmd = connection.CreateCommand())
{

    cmd.CommandText = sql;

    cmd.Parameters.AddRange(new[] { xmlParameter, returnParameter, familySentParameter });

    if (connection.State.Equals(ConnectionState.Closed)) connection.Open();

    using (var reader = cmd.ExecuteReader())
    {
        var entities = new List<string>();
        while (reader.Read())
        {
            Debug.WriteLine("Reader: " + reader.GetValue(0));
        }
    }
}

enter image description here

As a result, there are 3 SELECT. How do you get access to 2 and 3?

startNet
  • 274
  • 1
  • 10

0 Answers0