Esempio n. 1
0
        /// <summary>
        /// 执行查询命令
        /// </summary>
        /// <param name="p_SQL">要执行的sql命令或存储过程名</param>
        /// <param name="p_ParaList">参数集(null代表无参数)</param>
        /// <returns>填充了数据的DataSet</returns>
        /// <remarks></remarks>
        /// <param name="p_Type"></param>
        public static DataSet FExecQuery(string p_SQL, SqlParameter[] p_ParaList, CommandType p_Type)
        {
            BIM_DB_Helper._strSQL = p_SQL;
            SqlCommand command = BIM_DB_Helper.FCreateCommand(p_SQL, p_ParaList, p_Type);//创建sql命令对象

            command.CommandTimeout = 900000000;
            System.Diagnostics.Debug.Assert(null != command);

            DataSet        dsContain = new DataSet();
            SqlDataAdapter da        = new SqlDataAdapter(command);

            System.Diagnostics.Debug.Assert(null != dsContain);
            try
            {
                DateTime dtStart = DateTime.Now;
                da.Fill(dsContain);//执行并填充
                DateTime dtEnd = DateTime.Now;
                TimeSpan ts    = dtEnd - dtStart;
                return(dsContain);
            }
            catch (Exception e)
            {
                // ExceptionManager.Raise(this.GetType(), "$Error_Command_Execute", e);
                throw new Exception();
            }
            finally
            {
                command.Connection.Close();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 执行sql
        /// </summary>
        /// <param name="p_SQL">sql语句</param>
        /// <param name="p_ParaList">参数集(null代表无参数)</param>
        /// <param name="p_Type">类型</param>
        /// <returns>返回影响行数</returns>
        public static int FExecNonQuery(string p_SQL, SqlParameter[] p_ParaList, CommandType p_Type)
        {
            BIM_DB_Helper._strSQL = p_SQL;
            SqlCommand command = BIM_DB_Helper.FCreateCommand(p_SQL, p_ParaList, p_Type);//创建sql命令对象

            command.CommandTimeout = 13600;
            System.Diagnostics.Debug.Assert(null != command);
            SqlTransaction transaction;

            try
            {
                if (command.Connection.State == ConnectionState.Closed)
                {
                    command.Connection.Open();
                }
                transaction         = command.Connection.BeginTransaction("SampleTransaction");
                command.Transaction = transaction;
                try
                {
                    DateTime dtStart = DateTime.Now;
                    //log.Info("************StartDateTime:" + dtStart.ToString() + "," + dtStart.Millisecond);
                    //log.Info(" Parameter SQL:" + command.CommandText);
                    int i = command.ExecuteNonQuery();//执行命令
                    //DateTime dtEnd = DateTime.Now;
                    //TimeSpan ts = dtEnd - dtStart;
                    //log.Info("************EndDateTime:" + dtEnd.ToString() + "," + dtEnd.Millisecond + "*********"
                    //    + "Cost: " + ts.Seconds + ":" + ts.Milliseconds);
                    transaction.Commit();
                    return(i);
                }
                catch (Exception e)
                {
                    // log.Error(e.Message + " Parameter SQL:" + command.CommandText);
                    transaction.Rollback();
                    throw new Exception(e.Message);
                    //ExceptionManager.Raise(this.GetType(), "$Error_Command_Execute", e);
                }
            }
            finally
            {
                command.Connection.Close();
            }
        }