private void InitializeObjects(string StordName, StordeParameters Paramters, out SqlCommand CommandObject, out SqlDataAdapter DataAdapterObject, out DataSet DataSetObject) { InitializeObjects(StordName, out CommandObject, out DataAdapterObject, out DataSetObject); foreach (DictionaryEntry item in Paramters.AllParameters) { CommandObject.Parameters.AddWithValue( item.Key.ToString(), item.Value); } }
/// <summary> /// /// </summary> /// <param name="StordName"></param> /// <param name="Paramters"></param> /// <param name="eXecuteType"></param> /// <returns></returns> public object ExecuteSotord(string StordName, StordeParameters Paramters, ExecuteType eXecuteType) { if (transactionObject == null) { return(WithOutTransactions(StordName, Paramters, eXecuteType)); } else { return(WithTransactions(StordName, Paramters, eXecuteType)); } }
private object WithOutTransactions(string StordName, StordeParameters Paramters, ExecuteType eXecuteType) { object ObjectReturn = null; SqlConnection ConnectionObject; SqlCommand CommandObject; SqlDataAdapter DataAdapterObject; DataSet DataSetObject; if (TryConnectiongToServer() && Security.IsNullOrEmpty(StordName)) { InitializeObjects(StordName, Paramters, out ConnectionObject, out CommandObject, out DataAdapterObject, out DataSetObject); try { ConnectionObject.Open(); switch (eXecuteType) { case ExecuteType.ExecuteNonQuery: ObjectReturn = CommandObject.ExecuteNonQuery(); break; case ExecuteType.ExecuteReader: ObjectReturn = CommandObject.ExecuteReader(); break; case ExecuteType.ExecuteScalar: ObjectReturn = CommandObject.ExecuteScalar(); break; case ExecuteType.ExecuteXmlReader: ObjectReturn = CommandObject.ExecuteXmlReader(); break; case ExecuteType.SqlDataAdapterFill: DataAdapterObject.Fill(DataSetObject); ObjectReturn = DataSetObject; break; default: ObjectReturn = null; break; } return(ObjectReturn); } catch (Exception e) { this.erorrValue = e; return(null); } finally { if (ObjectReturn as SqlDataReader == null || !((SqlDataReader)ObjectReturn).HasRows) { ReleaseObjects(ref ConnectionObject); } ReleaseObjects(ref CommandObject); ReleaseObjects(ref DataAdapterObject); ReleaseObjects(ref DataSetObject); } } else { this.erorrValue = new NullReferenceException(); return(null); } }
private object WithTransactions(string StordName, StordeParameters Paramters, ExecuteType eXecuteType) { object ObjectReturn = null; if (transactionObject.Connection.State == ConnectionState.Open) { SqlCommand CommandObject; SqlDataAdapter DataAdapterObject; DataSet DataSetObject; InitializeObjects(StordName, Paramters, out CommandObject, out DataAdapterObject, out DataSetObject); try { switch (eXecuteType) { case ExecuteType.ExecuteNonQuery: ObjectReturn = CommandObject.ExecuteNonQuery(); break; case ExecuteType.ExecuteReader: ObjectReturn = CommandObject.ExecuteReader(); break; case ExecuteType.ExecuteScalar: ObjectReturn = CommandObject.ExecuteScalar(); break; case ExecuteType.ExecuteXmlReader: ObjectReturn = CommandObject.ExecuteXmlReader(); break; case ExecuteType.SqlDataAdapterFill: DataAdapterObject.Fill(DataSetObject); ObjectReturn = DataSetObject; break; default: ObjectReturn = null; break; } return(ObjectReturn); } catch (Exception e) { erorrValue = e; ReleaseObjects(ref CommandObject); ReleaseObjects(ref DataAdapterObject); ReleaseObjects(ref DataSetObject); if (RollbackTransaction()) { return("Transaction has Rollback"); } else { return(null); } } } else { this.erorrValue = new Exception("Connection has Closed"); return(null); } }