/// <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)); } }
/// <summary> /// 执行没有结果的查询 /// </summary> /// <param name="query">要执行的查询对象</param> /// <returns>查询所影响的行数</returns> public static int ExecuteNonQuery(this IDbExecutable query) { using (var context = query.Execute()) { return(context.RecordsAffected); } }
/// <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()); }
/// <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); } } }
/// <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); } } }