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