Example #1
0
        /// <summary>
        /// 返回一个DataTable
        /// </summary>
        /// <param name="commandText">SQL语句字符串</param>
        /// <param name="timeOut">超时限制</param>
        /// <returns></returns>
        public override DataTable GetDataTable(string commandText, int timeOut)
        {
            IBM.Data.Informix.IfxCommand cmd = new IBM.Data.Informix.IfxCommand(commandText);
            cmd.Connection = (IBM.Data.Informix.IfxConnection) this.connection;
            if (timeOut > 30)
            {
                cmd.CommandTimeout = timeOut;
            }
            if (isInTransaction)
            {
                cmd.Transaction = (IBM.Data.Informix.IfxTransaction)transaction;
            }

            IBM.Data.Informix.IfxDataAdapter adapter = new IBM.Data.Informix.IfxDataAdapter((IBM.Data.Informix.IfxCommand)cmd);
            try
            {
                DataTable dt = new DataTable();
                adapter.Fill(dt);
                return(dt);
            }
            catch (Exception err)
            {
                throw new EntityException(err.Message);
            }
            finally
            {
                cmd.Dispose();
                cmd = null;
                adapter.Dispose();
                adapter = null;
            }
        }
Example #2
0
        /// <summary>
        /// 执行插入一条记录 适用于有 自动生成标识的列
        /// </summary>
        /// <param name="commandText">SQL语句字符串</param>
        /// <param name="identity">自动增长列在插入记录是产生的序号</param>
        /// <param name="timeOut">超时限制</param>
        /// <returns></returns>
        public override int InsertRecord(string commandText, out object identity, int timeOut)
        {
            if (GetIdentityString() == null)
            {
                throw new EntityException("无法取得自增长列ID");
            }
            int result = 0;

            IBM.Data.Informix.IfxCommand cmd = new IBM.Data.Informix.IfxCommand(commandText);
            if (isInTransaction)
            {
                cmd.Transaction = (IBM.Data.Informix.IfxTransaction)transaction;
            }
            cmd.Connection = (IBM.Data.Informix.IfxConnection)connection;
            if (timeOut > 30)
            {
                cmd.CommandTimeout = timeOut;
            }
            try
            {
                result          = cmd.ExecuteNonQuery();
                cmd.CommandText = GetIdentityString();
                identity        = Convert.ToInt32(cmd.ExecuteScalar());
                return(result);
            }
            catch (Exception err)
            {
                throw new EntityException(err.Message);
            }
            finally
            {
                cmd.Dispose();
                cmd = null;
            }
        }
Example #3
0
        /// <summary>
        /// 执行一个命令返回一个数据结果
        /// </summary>
        /// <param name="commandText">SQL语句字符串</param>
        /// <param name="timeOut">超时限制</param>
        /// <returns></returns>
        public override object GetDataResult(string commandText, int timeOut)
        {
            object Result = null;

            IBM.Data.Informix.IfxCommand cmd = new IBM.Data.Informix.IfxCommand(commandText);
            if (isInTransaction)
            {
                cmd.Transaction = (IBM.Data.Informix.IfxTransaction)transaction;
            }
            cmd.Connection = (IBM.Data.Informix.IfxConnection)connection;
            if (timeOut > 30)
            {
                cmd.CommandTimeout = timeOut;
            }
            try
            {
                Result = cmd.ExecuteScalar();
                return(Result);
            }
            catch (Exception err)
            {
                throw new EntityException(err.Message);
            }
            finally
            {
                cmd.Dispose();
                cmd = null;
            }
        }
Example #4
0
        /// <summary>
        /// 执行一个语句,返回执行情况
        /// </summary>
        /// <param name="commandText">SQL语句字符串</param>
        /// <param name="timeOut">超时限制</param>
        /// <returns></returns>
        public override int DoCommand(string commandText, int timeOut)
        {
            int result = 0;

            IBM.Data.Informix.IfxCommand cmd = new IBM.Data.Informix.IfxCommand(commandText);
            if (isInTransaction)
            {
                cmd.Transaction = (IBM.Data.Informix.IfxTransaction)transaction;
            }
            cmd.Connection = (IBM.Data.Informix.IfxConnection)connection;
            if (timeOut > 30)
            {
                cmd.CommandTimeout = timeOut;
            }
            try
            {
                result = cmd.ExecuteNonQuery();
                return(result);
            }
            catch (Exception err)
            {
                throw new EntityException(err.Message);
            }
            finally
            {
                cmd.Dispose();
                cmd = null;
            }
        }
Example #5
0
 /// <summary>
 /// 返回一个DataReader
 /// </summary>
 /// <param name="commandText">SQL语句字符串</param>
 /// <param name="timeOut">超时限制</param>
 /// <returns></returns>
 public override IDataReader GetDataReader(string commandText, int timeOut)
 {
     IBM.Data.Informix.IfxCommand cmd = new IBM.Data.Informix.IfxCommand(commandText);
     cmd.Connection = (IBM.Data.Informix.IfxConnection) this.connection;
     if (timeOut > 30)
     {
         cmd.CommandTimeout = timeOut;
     }
     if (isInTransaction)
     {
         cmd.Transaction = (IBM.Data.Informix.IfxTransaction)transaction;
     }
     try
     {
         IBM.Data.Informix.IfxDataReader reader = (IBM.Data.Informix.IfxDataReader)cmd.ExecuteReader();
         return(reader);
     }
     catch (Exception err)
     {
         throw new EntityException(err.Message);
     }
     finally
     {
         cmd.Dispose();
         cmd = null;
     }
 }
Example #6
0
 /// <summary>
 ///  返回一个IDataAdpter
 /// </summary>
 /// <param name="commandText">SQL语句字符串</param>
 /// <returns></returns>
 public override DbDataAdapter GetAdapter(string commandText)
 {
     IBM.Data.Informix.IfxDataAdapter adapter = new IBM.Data.Informix.IfxDataAdapter();
     IBM.Data.Informix.IfxCommand     cmd     = new IBM.Data.Informix.IfxCommand(commandText);
     adapter.SelectCommand = (IBM.Data.Informix.IfxCommand)cmd;
     cmd.Connection        = (IBM.Data.Informix.IfxConnection)connection;
     if (isInTransaction)
     {
         cmd.Transaction = (IBM.Data.Informix.IfxTransaction)transaction;
     }
     return(adapter);
 }
Example #7
0
        /// <summary>
        /// 返回一个DataRow
        /// </summary>
        /// <param name="commandText">SQL语句字符串</param>
        /// <param name="timeOut">超时限制</param>
        /// <returns></returns>
        public override DataRow GetDataRow(string commandText, int timeOut)
        {
            IBM.Data.Informix.IfxCommand cmd = new IBM.Data.Informix.IfxCommand(commandText);
            cmd.Connection = (IBM.Data.Informix.IfxConnection) this.connection;                                         //添加连接
            if (timeOut > 30)
            {
                cmd.CommandTimeout = timeOut;
            }
            DataRow r;

            IBM.Data.Informix.IfxDataAdapter adapter = new IBM.Data.Informix.IfxDataAdapter();
            adapter.SelectCommand = (IBM.Data.Informix.IfxCommand)cmd;
            if (isInTransaction)
            {
                cmd.Transaction = (IBM.Data.Informix.IfxTransaction)transaction;
            }
            try
            {
                DataTable dt = new DataTable();
                adapter.Fill(dt);

                if (dt.Rows.Count > 0)
                {
                    r = dt.Rows[0];
                }
                else
                {
                    r = null;
                }
                return(r);
            }
            catch (Exception err)
            {
                throw new EntityException(err.Message);
            }
            finally
            {
                cmd.Dispose();
                cmd = null;
                adapter.Dispose();
                adapter = null;
            }
        }