コード例 #1
0
 /// <summary>
 /// 执行查询并将第一个结果集包装成 DataTable 返回
 /// </summary>
 /// <param name="query">要执行的查询对象</param>
 /// <returns>查询结果</returns>
 public static DataTable ExecuteDataTable(this IDbExecutable query)
 {
     using (var context = query.Execute())
     {
         return(context.LoadDataTable(0, 0));
     }
 }
コード例 #2
0
 /// <summary>
 /// 执行没有结果的查询
 /// </summary>
 /// <param name="query">要执行的查询对象</param>
 /// <returns>查询所影响的行数</returns>
 public static int ExecuteNonQuery(this IDbExecutable query)
 {
     using (var context = query.Execute())
     {
         return(context.RecordsAffected);
     }
 }
コード例 #3
0
        /// <summary>
        /// 执行查询并将所有结果集包装成 DataTable 返回
        /// </summary>
        /// <param name="query">要执行的查询对象</param>
        /// <returns>查询结果</returns>
        public static DataTable[] ExecuteAllDataTables(this IDbExecutable 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());
        }
コード例 #4
0
        /// <summary>
        /// 执行查询并返回首行首列
        /// </summary>
        /// <param name="query">要执行的查询对象</param>
        /// <returns>查询结果</returns>
        public static object ExecuteScalar(this IDbExecutable query)
        {
            using (var context = query.Execute())
            {
                var record = context.ReadRecord();
                if (record != null && record.FieldCount > 0)
                {
                    return(record[0]);
                }

                else
                {
                    return(null);
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// 执行查询并返回首行
        /// </summary>
        /// <param name="query">要执行的查询对象</param>
        /// <returns>查询结果</returns>
        public static DataRow ExecuteFirstRow(this IDbExecutable 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);
                }
            }
        }