示例#1
0
        public SqlCommand CreateSqlComd(string strSql, DbParameters p)
        {
            try
            {
                SqlCommand comd = CreateSqlComd(strSql);

                int len = p.Length;
                if (len > 0)
                {
                    for (int i = 0; i < len; i++)
                    {
                        comd.Parameters.Add(p[i]);
                    }
                }
                return(comd);
            }
            catch (System.Exception ex)
            {
                Log.LogError("DbCommand->CreateSqlcomd(s,p) 出错\r\n" + ex.Message);
                throw new Exception(ex.Message);
            }
        }
示例#2
0
        /// <summary>
        /// 查看特定数据库的日志文件大小
        /// </summary>
        public static DataTable GetLogSpace(string dataName)
        {
            try
            {
                string       sql = @"
                Begin
                    --创建临时表--
                    CREATE TABLE tempdb.dbo.#tbl_DBLogSpaceUsage  
                    (  
                          DatabaseName NVARCHAR(128) ,  
                          LogSize NVARCHAR(25) ,  
                          LogSpaceUsed NVARCHAR(25) ,  
                          [Status] TINYINT  
                    )
                    INSERT INTO dbo.#tbl_DBLogSpaceUsage EXEC ('DBCC SQLPERF(LogSpace)');
                                
                    --查询特定数据库的结果-- 
                    SELECT  DatabaseName ,  
                            LogSize AS LogSizeInMB ,  
                            LogSpaceUsed LogspaceUsed_In_Percent ,  
                            [Status]  
                    FROM tempdb.dbo.#tbl_DBLogSpaceUsage  
                    WHERE Databasename = @DataBaseName   

                    --删除临时表--
                    DROP TABLE tempdb.dbo.#tbl_DBLogSpaceUsage  
                End             
            ";
                DbParameters p   = new DbParameters();
                p.Add("@DataBaseName", dataName);

                return(DbComd.CreateSqlDataTable(sql, p));
            }
            catch (System.Exception ex)
            {
                throw new Exception("\n---- " + DateTime.Now.ToString() + " GetLogSpace() 报错:----\n" + ex.Message + "--end--\n");
                return(null);
            }
        }
示例#3
0
        /// <summary>
        /// 执行并返回输出参数:默认输出参数 @Result Varchar(50)
        /// </summary>
        public string ExecuteOut(string spName, DbParameters p)
        {
            SqlCommand comd = CreateComd(spName, p);

            comd.Parameters.Add(new SqlParameter("@Result", SqlDbType.VarChar, 50));
            comd.Parameters["@Result"].Direction = ParameterDirection.Output;

            try
            {
                ConnOpen(ref comd);
                comd.ExecuteNonQuery();
                object o = comd.Parameters["@Result"].Value;
                ConnClose(ref comd);

                return((o == null) ? "" : o.ToString());
            }
            catch (System.Exception ex)
            {
                ConnClose(ref comd);
                Log.LogError("DbCommand->ExecuteOut() 出错\r\n" + ex.Message);
                throw new Exception(ex.Message);
            }
        }
示例#4
0
        /// <summary>
        /// 根据SQL语句和参数,生成DataAdapter对象
        /// </summary>
        public SqlDataAdapter CreateSqlAdapter(string strSql, DbParameters p)
        {
            try
            {
                SqlDataAdapter apter = CreateSqlAdapter(strSql);

                int len = p.Length;
                if (len > 0)
                {
                    for (int i = 0; i < len; i++)
                    {
                        apter.SelectCommand.Parameters.Add(p[i]);
                    }
                }

                return(apter);
            }
            catch (System.Exception ex)
            {
                Log.LogError("DbCommand->CreateSqlAdapter(s,p) 出错\r\n" + ex.Message);
                throw new Exception(ex.Message);
            }
        }
示例#5
0
        public int ExecuteSql(string sql, DbParameters p)
        {
            SqlCommand comd = CreateSqlComd(sql, p);

            return(ToExecute(comd));
        }
示例#6
0
        /// <summary>
        /// 根据存储过程和参数执行
        /// </summary>
        public int Execute(string spName, DbParameters p)
        {
            SqlCommand comd = CreateComd(spName, p);

            return(ToExecute(comd));
        }
示例#7
0
        /// <summary>
        /// 创建实体列表
        /// </summary>
        public IList <T> CreateList <T>(string sql, DbParameters p) where T : new()
        {
            DataTable dt = CreateSqlDataTable(sql, p);

            return(CreateList <T>(dt));
        }
示例#8
0
        /// <summary>
        /// 根据SQL语句和参数创建实体
        /// </summary>
        public T CreateEntity <T>(string sql, DbParameters p) where T : new()
        {
            DataTable dt = CreateSqlDataTable(sql, p);

            return(CreateEntity <T>(dt));
        }
示例#9
0
        /// <summary>
        /// 根据SQL语句和参数,创建Scalar对象
        /// </summary>
        public object CreateSqlScalar(string strSql, DbParameters p)
        {
            SqlCommand comd = CreateSqlComd(strSql, p);

            return(GetScalar(comd));
        }
示例#10
0
        /// <summary>
        /// 根据SQL语句和参数,创建DataSet
        /// </summary>
        public DataSet CreateSqlDataSet(string strSql, DbParameters p)
        {
            SqlDataAdapter adapter = CreateSqlAdapter(strSql, p);

            return(GetDataSet(adapter));
        }
示例#11
0
        /// <summary>
        /// 根据存储过程和参数创建 DataSet
        /// </summary>
        public DataSet CreateDataSet(string spName, DbParameters p)
        {
            SqlDataAdapter adapter = CreateAdapter(spName, p);

            return(GetDataSet(adapter));
        }
示例#12
0
        /// <summary>
        /// 根据SQL语句和参数,创建单行的SqlDataReader
        /// </summary>
        public SqlDataReader CreateSqlSingleDataReader(string strSql, DbParameters p)
        {
            SqlCommand comd = CreateSqlComd(strSql, p);

            return(GetSingleDataReader(comd));
        }
示例#13
0
        /// <summary>
        /// 根据存储过程和参数生成SqlDataReader
        /// </summary>
        public SqlDataReader CreateDataReader(string spName, DbParameters p)
        {
            SqlCommand comd = CreateComd(spName, p);

            return(GetDataReader(comd));
        }
示例#14
0
 public CommandInfo(string sqlText, DbParameters para, EffentNextType type)
 {
     this.CommandText    = sqlText;
     this.Parameters     = para;
     this.EffentNextType = type;
 }
示例#15
0
 public CommandInfo(string sqlText, DbParameters para)
 {
     this.CommandText = sqlText;
     this.Parameters  = para;
 }