예제 #1
0
 /// <summary>
 /// 执行没有结果的查询
 /// </summary>
 /// <param name="query">要执行的查询对象</param>
 /// <returns>查询所影响的行数</returns>
 public static int ExecuteNonQuery(this IDbExecutableQuery query)
 {
     using (var context = query.Execute())
     {
         return(context.DataReader.RecordsAffected);
     }
 }
예제 #2
0
 /// <summary>
 /// 执行查询并将第一个结果集包装成 DataTable 返回
 /// </summary>
 /// <param name="query">要执行的查询对象</param>
 /// <returns>查询结果</returns>
 public static DataTable ExecuteDataTable(this IDbExecutableQuery query)
 {
     using (var context = query.Execute())
     {
         return(context.LoadDataTable(0, 0));
     }
 }
예제 #3
0
        /// <summary>
        /// 执行查询并将第一个结果集包装成 DataTable 返回
        /// </summary>
        /// <param name="query">要执行的查询对象</param>
        /// <returns>查询结果</returns>
        public static DataTable ExecuteDataTable(this IDbExecutableQuery query)
        {
            using (var context = query.Execute())
            {
                var data = new DataTable();
                data.Load(context.DataReader);

                return(data);
            }
        }
예제 #4
0
        /// <summary>
        /// 执行查询并将所有结果集包装成 DataTable 返回
        /// </summary>
        /// <param name="query">要执行的查询对象</param>
        /// <returns>查询结果</returns>
        public static DataTable[] ExecuteAllDataTables(this IDbExecutableQuery query)
        {
            List <DataTable> dataTables = new List <DataTable>();

            using (var context = query.Execute())
            {
                do
                {
                    dataTables.Add(context.LoadDataTable(0, 0));
                } while (context.NextResult());
            }

            return(dataTables.ToArray());
        }
예제 #5
0
        /// <summary>
        /// 执行查询并返回首行首列
        /// </summary>
        /// <param name="query">要执行的查询对象</param>
        /// <returns>查询结果</returns>
        public static object ExecuteScalar(this IDbExecutableQuery query)
        {
            using (var context = query.Execute())
            {
                if (context.DataReader.Read() && context.DataReader.FieldCount > 0)
                {
                    return(context.DataReader[0]);
                }

                else
                {
                    return(null);
                }
            }
        }
예제 #6
0
        /// <summary>
        /// 执行查询并返回首行首列
        /// </summary>
        /// <param name="query">要执行的查询对象</param>
        /// <returns>查询结果</returns>
        public static object ExecuteScalar(this IDbExecutableQuery query)
        {
            using (var context = query.Execute())
            {
                var record = context.ReadRecord();
                if (record != null && record.FieldCount > 0)
                {
                    return(record[0]);
                }

                else
                {
                    return(null);
                }
            }
        }
예제 #7
0
        /// <summary>
        /// 执行查询并将所有结果集包装成 DataTable 返回
        /// </summary>
        /// <param name="query">要执行的查询对象</param>
        /// <returns>查询结果</returns>
        public static DataTable[] ExecuteAllDataTables(this IDbExecutableQuery query)
        {
            List <DataTable> dataTables = new List <DataTable>();

            using (var context = query.Execute())
            {
                do
                {
                    var data = new DataTable();
                    data.Load(context.DataReader);

                    dataTables.Add(data);
                } while (context.DataReader.NextResult());
            }

            return(dataTables.ToArray());
        }
예제 #8
0
        /// <summary>
        /// 执行查询并返回首行
        /// </summary>
        /// <param name="query">要执行的查询对象</param>
        /// <returns>查询结果</returns>
        public static DataRow ExecuteFirstRow(this IDbExecutableQuery query)
        {
            //UNDONE

            using (var context = query.Execute())
            {
                var data = context.LoadDataTable(0, 1);
                if (data.Rows.Count > 0)
                {
                    return(data.Rows[0]);
                }

                else
                {
                    return(null);
                }
            }
        }