Beispiel #1
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;
            }
        }
Beispiel #2
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;
            }
        }