public static void HandleException(out SqlString aParam1, out SqlInt32 aParam2, out SqlInt32 aParam3,
SqlInt32 aParam4)
{
using (var connect = new SqlConnection(ConnectionString))
{
try
{
connect.Open();
using (var command = new SqlCommand("[dbo].[MyPROC]", connect))
{
command.CommandType = CommandType.StoredProcedure;
Dictionary<string, SqlParameter> dictionary = new Dictionary<string, SqlParameter>();
dictionary.Add("ErrorMessage", new SqlParameter("@Param1", SqlDbType.NVarChar, 2048));
dictionary.Add("ErrorNumber", new SqlParameter("@Param2", SqlDbType.Int));
dictionary.Add("ErrorState", new SqlParameter("@Param3", SqlDbType.Int));
dictionary.Add("ErrorProcID", new SqlParameter("@Param4", SqlDbType.Int));
foreach (var kvp in dictionary)
{
command.Parameters.Add(kvp.Value);
if (kvp.Key != "ErrorProcID")
{
kvp.Value.Direction = ParameterDirection.Output;
}
}
dictionary["Param4"].Value = 0;
command.ExecuteNonQuery();
aParam1= (SqlString) dictionary["Param1"].Value;
aParam2= (SqlInt32) dictionary["Param2 "].Value;
aParam3= (SqlInt32) dictionary["Param3 "].Value;
}
}
finally
{
connect.Close();
}
}
}
Мой вопрос скорее всего спортивный интерес.