Beispiel #1
0
        public static object ExecuteScalar(this DatabaseFacade facade, string sql, params object[] parameters)
        {
            var command = CreateCommand(facade, sql, out DbConnection conn, parameters);
            var obj     = command.ExecuteScalar();

            command.Parameters.Clear();
            if (facade.CurrentTransaction == null)
            {
                facade.CloseConnection(); //没有事务时,关闭连接
            }
            return(obj);
        }
Beispiel #2
0
        public static DataTable SqlQuery(this DatabaseFacade facade, string sql, params object[] parameters)
        {
            var command = CreateCommand(facade, sql, out DbConnection conn, parameters);
            var reader  = command.ExecuteReader();

            command.Parameters.Clear();
            var dt = new DataTable();

            dt.Load(reader);
            reader.Close();
            if (facade.CurrentTransaction == null)
            {
                facade.CloseConnection(); //没有事务时,关闭连接
            }
            //conn.Close();  //在事务中时,不需要关闭连接
            return(dt);
        }