예제 #1
0
 public static System.Data.DataSet Query(string connectionString, string SQLString, params OracleParameter[] cmdParms)
 {
     System.Data.DataSet result;
     using (OracleConnection oracleConnection = new OracleConnection(connectionString))
     {
         OracleCommand oracleCommand = new OracleCommand();
         OracleHelper.PrepareCommand(oracleCommand, oracleConnection, null, SQLString, cmdParms);
         using (OracleDataAdapter oracleDataAdapter = new OracleDataAdapter(oracleCommand))
         {
             System.Data.DataSet dataSet = new System.Data.DataSet();
             try
             {
                 oracleDataAdapter.Fill(dataSet, "ds");
                 oracleCommand.Parameters.Clear();
             }
             catch (OracleException ex)
             {
                 throw new Exception(ex.Message);
             }
             finally
             {
                 if (oracleConnection.State != System.Data.ConnectionState.Closed)
                 {
                     oracleConnection.Close();
                 }
             }
             result = dataSet;
         }
     }
     return(result);
 }
예제 #2
0
        public static object ExecuteScalar(OracleConnection connectionString, System.Data.CommandType cmdType, string cmdText, params OracleParameter[] commandParameters)
        {
            OracleCommand oracleCommand = new OracleCommand();

            OracleHelper.PrepareCommand(oracleCommand, connectionString, null, cmdType, cmdText, commandParameters);
            object result = oracleCommand.ExecuteScalar();

            oracleCommand.Parameters.Clear();
            return(result);
        }
예제 #3
0
        public static int ExecuteNonQuery(OracleTransaction trans, System.Data.CommandType cmdType, string cmdText, params OracleParameter[] commandParameters)
        {
            OracleCommand oracleCommand = new OracleCommand();

            OracleHelper.PrepareCommand(oracleCommand, trans.Connection, trans, cmdType, cmdText, commandParameters);
            int result = oracleCommand.ExecuteNonQuery();

            oracleCommand.Parameters.Clear();
            return(result);
        }
예제 #4
0
        public static int ExecuteNonQuery(string connectionString, string cmdText)
        {
            OracleCommand    oracleCommand = new OracleCommand();
            OracleConnection conn          = new OracleConnection(connectionString);

            OracleHelper.PrepareCommand(oracleCommand, conn, null, System.Data.CommandType.Text, cmdText, null);
            int result = oracleCommand.ExecuteNonQuery();

            oracleCommand.Parameters.Clear();
            return(result);
        }
예제 #5
0
        public static int ExecuteNonQuery(string connectionString, System.Data.CommandType cmdType, string cmdText, params OracleParameter[] commandParameters)
        {
            OracleCommand oracleCommand = new OracleCommand();
            int           result;

            using (OracleConnection oracleConnection = new OracleConnection(connectionString))
            {
                OracleHelper.PrepareCommand(oracleCommand, oracleConnection, null, cmdType, cmdText, commandParameters);
                int num = oracleCommand.ExecuteNonQuery();
                oracleConnection.Close();
                oracleCommand.Parameters.Clear();
                result = num;
            }
            return(result);
        }
예제 #6
0
        public static object ExecuteScalar(OracleTransaction transaction, System.Data.CommandType commandType, string commandText, params OracleParameter[] commandParameters)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException("transaction");
            }
            if (transaction != null && transaction.Connection == null)
            {
                throw new ArgumentException("The transaction was rollbacked\tor commited, please\tprovide\tan open\ttransaction.", "transaction");
            }
            OracleCommand oracleCommand = new OracleCommand();

            OracleHelper.PrepareCommand(oracleCommand, transaction.Connection, transaction, commandType, commandText, commandParameters);
            object result = oracleCommand.ExecuteScalar();

            oracleCommand.Parameters.Clear();
            return(result);
        }
예제 #7
0
        public static OracleDataReader ExecuteReader(string connectionString, System.Data.CommandType cmdType, string cmdText, params OracleParameter[] commandParameters)
        {
            OracleCommand    oracleCommand    = new OracleCommand();
            OracleConnection oracleConnection = new OracleConnection(connectionString);
            OracleDataReader result;

            try
            {
                OracleHelper.PrepareCommand(oracleCommand, oracleConnection, null, cmdType, cmdText, commandParameters);
                OracleDataReader oracleDataReader = oracleCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
                oracleCommand.Parameters.Clear();
                result = oracleDataReader;
            }
            catch
            {
                oracleConnection.Close();
                throw;
            }
            return(result);
        }
예제 #8
0
        public static bool ExecuteSqlTran(string conStr, List <CommandInfo> cmdList)
        {
            bool result;

            using (OracleConnection oracleConnection = new OracleConnection(conStr))
            {
                oracleConnection.Open();
                OracleCommand oracleCommand = new OracleCommand();
                oracleCommand.Connection = oracleConnection;
                OracleTransaction oracleTransaction = oracleConnection.BeginTransaction();
                oracleCommand.Transaction = oracleTransaction;
                try
                {
                    foreach (CommandInfo current in cmdList)
                    {
                        if (!string.IsNullOrEmpty(current.CommandText))
                        {
                            OracleHelper.PrepareCommand(oracleCommand, oracleConnection, oracleTransaction, System.Data.CommandType.Text, current.CommandText, (OracleParameter[])current.Parameters);
                            if (current.EffentNextType == EffentNextType.WhenHaveContine || current.EffentNextType == EffentNextType.WhenNoHaveContine)
                            {
                                if (current.CommandText.ToLower().IndexOf("count(") == -1)
                                {
                                    oracleTransaction.Rollback();
                                    throw new Exception("Oracle:违背要求" + current.CommandText + "必须符合select count(..的格式");
                                }
                                object obj = oracleCommand.ExecuteScalar();
                                if (obj == null && obj == DBNull.Value)
                                {
                                }
                                bool flag = Convert.ToInt32(obj) > 0;
                                if (current.EffentNextType == EffentNextType.WhenHaveContine && !flag)
                                {
                                    oracleTransaction.Rollback();
                                    throw new Exception("Oracle:违背要求" + current.CommandText + "返回值必须大于0");
                                }
                                if (current.EffentNextType == EffentNextType.WhenNoHaveContine && flag)
                                {
                                    oracleTransaction.Rollback();
                                    throw new Exception("Oracle:违背要求" + current.CommandText + "返回值必须等于0");
                                }
                            }
                            else
                            {
                                int num = oracleCommand.ExecuteNonQuery();
                                if (current.EffentNextType == EffentNextType.ExcuteEffectRows && num == 0)
                                {
                                    oracleTransaction.Rollback();
                                    throw new Exception("Oracle:违背要求" + current.CommandText + "必须有影像行");
                                }
                            }
                        }
                    }
                    oracleTransaction.Commit();
                    result = true;
                }
                catch (OracleException ex)
                {
                    oracleTransaction.Rollback();
                    throw ex;
                }
                finally
                {
                    if (oracleConnection.State != System.Data.ConnectionState.Closed)
                    {
                        oracleConnection.Close();
                    }
                }
            }
            return(result);
        }