public void Dispose() { if (stpResult != null) { stpResult.Fields.Clear(); stpResult.Records.Clear(); stpResult = null; } }
/// <summary>Executes the StoredProcedure and Returns it's Result.</summary> protected int executeProcedure() { //Create a new Sql Connection using (SqlConnection connection = new SqlConnection(connectionString)) { //try to open it connection.Open(); //Create a new Resultset stpResult = new stpResult(); //Build the Command using (SqlCommand command = new SqlCommand(storedProcedureName, connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(sqlParameters.ToArray()); SqlParameter returnValue = new SqlParameter("@RETURN_VALUE", SqlDbType.Int) { Direction = ParameterDirection.ReturnValue }; command.Parameters.Add(returnValue); using (SqlDataReader reader = command.ExecuteReader()) { bool fieldsCreated = false; while (reader.Read()) { //First create the Fields which are required for accessing the Data via Columnnames if (!fieldsCreated) { for (int i = 0; i < reader.FieldCount; i++) { stpResult.Fields.Add(reader.GetName(i)); } fieldsCreated = true; } var recordSet = new Dictionary <string, object>(); for (int k = 0; k < reader.FieldCount; k++) { recordSet.Add(stpResult.Fields[k], reader[k]); } stpResult.Records.Add(recordSet); } } if (returnValue.Value == null) { throw new Exception("Unknown Error during SP Execution"); } return((int)returnValue.Value); } } }
/// <summary>Executes the StoredProcedure and Returns it's Result.</summary> protected int executeProcedure() { //Create a new Sql Connection using(SqlConnection connection = new SqlConnection(connectionString)) { //try to open it connection.Open(); //Create a new Resultset stpResult = new stpResult(); //Build the Command using (SqlCommand command = new SqlCommand(storedProcedureName, connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(sqlParameters.ToArray()); SqlParameter returnValue = new SqlParameter("@RETURN_VALUE", SqlDbType.Int) {Direction = ParameterDirection.ReturnValue}; command.Parameters.Add(returnValue); using(SqlDataReader reader = command.ExecuteReader()) { bool fieldsCreated = false; while (reader.Read()) { //First create the Fields which are required for accessing the Data via Columnnames if(!fieldsCreated) { for (int i = 0; i < reader.FieldCount;i++ ) stpResult.Fields.Add(reader.GetName(i)); fieldsCreated = true; } var recordSet = new Dictionary<string, object>(); for (int k = 0; k < reader.FieldCount; k++) recordSet.Add(stpResult.Fields[k], reader[k]); stpResult.Records.Add(recordSet); } } if (returnValue.Value == null) throw new Exception("Unknown Error during SP Execution"); return (int) returnValue.Value; } } }