Exemple #1
0
            private object WithOutTransactions(string StordName, ExecuteType eXecuteType)
            {
                object         ObjectReturn = null;
                SqlConnection  ConnectionObject;
                SqlCommand     CommandObject;
                SqlDataAdapter DataAdapterObject;
                DataSet        DataSetObject;

                if (TryConnectiongToServer() && Security.IsNullOrEmpty(StordName))
                {
                    InitializeObjects(StordName, 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);
                }
            }
Exemple #2
0
            private object WithTransactions(string StordName, ExecuteType eXecuteType)
            {
                object ObjectReturn = null;

                if (transactionObject.Connection.State == ConnectionState.Open)
                {
                    SqlCommand     CommandObject;
                    SqlDataAdapter DataAdapterObject;
                    DataSet        DataSetObject;
                    InitializeObjects(StordName, 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);
                }
            }