public T GetResult <T>(string sql, SqlParameter[] para)
        {
            if (SQLWordFilte.CheckSql(sql))
            {
                throw new Exception("您提供的关键字有可能危害数据库,已阻止执行");
            }
            try
            {
                DataSet ds = ExecuteQuery(sql, para);

                if (ds.Tables.Count == 0)
                {
                    return(default(T));
                }

                if (ds.Tables[0].Rows.Count == 0)
                {
                    return(default(T));
                }

                object v = ds.Tables[0].Rows[0][0];

                return((T)Convert.ChangeType(v, typeof(T)));
            }
            catch (Exception)
            {
                return(default(T));
            }
        }
        public object GetResult(string sql)
        {
            if (SQLWordFilte.CheckSql(sql))
            {
                throw new Exception("您提供的关键字有可能危害数据库,已阻止执行");
            }
            try
            {
                DataSet ds = ExecuteQuery(sql);

                if (ds.Tables.Count == 0)
                {
                    return(null);
                }

                if (ds.Tables[0].Rows.Count == 0)
                {
                    return(null);
                }

                object v = ds.Tables[0].Rows[0][0];

                return(v);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message + "\r\n" + sql);
            }
        }
        public IEnumerable <ExpandoObject> ExecuteExpandoObjects(string sql, params SqlParameter[] cmdParms)
        {
            if (SQLWordFilte.CheckSql(sql))
            {
                throw new Exception("您提供的关键字有可能危害数据库,已阻止执行");
            }
            DataSet ds = ExecuteQuery(string.Format(sql), cmdParms);

            if (ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
            {
                yield break;
            }

            foreach (DataTable table in ds.Tables)
            {
                foreach (DataRow row in table.Rows)
                {
                    IDictionary <string, object> expando = new ExpandoObject();
                    foreach (DataColumn column in table.Columns)
                    {
                        expando.Add(column.Caption, row[column]);
                    }

                    yield return((ExpandoObject)expando);
                }
            }
        }
        public ExpandoObject ExecuteExpandoObject(string sql)
        {
            if (SQLWordFilte.CheckSql(sql))
            {
                throw new Exception("您提供的关键字有可能危害数据库,已阻止执行");
            }
            DataSet ds = ExecuteQuery(string.Format(sql));

            if (ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
            {
                return(null);
            }

            foreach (DataTable table in ds.Tables)
            {
                foreach (DataRow row in table.Rows)
                {
                    IDictionary <string, object> expando = new ExpandoObject();
                    foreach (DataColumn column in table.Columns)
                    {
                        expando.Add(column.Caption, row[column]);
                    }

                    return((ExpandoObject)expando);
                }
            }
            return(null);
        }
 public DataSet ExecuteQuery(string sql, params SqlParameter[] cmdParms)
 {
     if (SQLWordFilte.CheckSql(sql))
     {
         throw new Exception("您提供的关键字有可能危害数据库,已阻止执行");
     }
     try
     {
         Session.Open();
         var ds  = new DataSet();
         var cmd = new SqlCommand();
         cmd            = PrepareCommand(cmd, sql, cmdParms);
         cmd.Connection = Session.Connection;
         var command = new SqlDataAdapter(cmd);
         command.Fill(ds);
         return(ds);
     }
     catch (SqlException ex)
     {
         throw new Exception(ex.Message + "\r\n" + sql);
     }
     finally
     {
         //session.Connection.Close();
     }
 }
        public void ExecuteSQL(string sql)
        {
            if (SQLWordFilte.CheckSql(sql))
            {
                throw new Exception("您提供的关键字有可能危害数据库,已阻止执行");
            }
            var cmd = new SqlCommand(sql);

            Session.AddCommands(cmd);
            //int rows = Session.Commit();
            //return rows;
        }
 public IDataReader ExecuteQueryReader(string sql)
 {
     if (SQLWordFilte.CheckSql(sql))
     {
         throw new Exception("您提供的关键字有可能危害数据库,已阻止执行");
     }
     try
     {
         Session.Open();
         var cmd = new SqlCommand(sql);
         cmd.Connection = Session.Connection;
         return(cmd.ExecuteReader());
     }
     catch (SqlException ex)
     {
         throw new Exception(ex.Message + "\r\n" + sql);
     }
 }
        public DataSet ExecuteQuery(string sql)
        {
            if (SQLWordFilte.CheckSql(sql))
            {
                throw new Exception("您提供的关键字有可能危害数据库,已阻止执行");
            }
            try
            {
                Session.Open();
                var ds  = new DataSet();
                var cmd = new SqlCommand(sql)
                {
                    Connection = Session.Connection
                };
                var command = new SqlDataAdapter(cmd);

                command.Fill(ds);
                return(ds);
            }
            catch (SqlException ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public IEnumerable <T> GetRowsResults <T>(string sql)
        {
            if (SQLWordFilte.CheckSql(sql))
            {
                throw new Exception("您提供的关键字有可能危害数据库,已阻止执行");
            }
            DataSet ds = ExecuteQuery(sql);

            if (ds.Tables.Count == 0)
            {
                yield return(default(T));
            }

            if (ds.Tables[0].Rows.Count == 0)
            {
                yield return(default(T));
            }

            foreach (DataRow r in ds.Tables[0].Rows)
            {
                object v = r[0];
                yield return((T)Convert.ChangeType(v, typeof(T)));
            }
        }