// 分页批量查询示例 // 适用插件:Operation/Report/Task // 依赖 API:DBUtils // 相关检查:大结果集推荐分页,避免一次性加载过多数据 using System.Collections.Generic; using System.Data; using Kingdee.BOS; using Kingdee.BOS.App.Data; using Kingdee.BOS.ServiceHelper; public class BatchQuerySample { private Context ctx; public void BatchQueryWithPaging() { int batchSize = 1000; int offset = 0; List allBillNos = new List(); while (true) { string sql = string.Format( "SELECT FBILLNO FROM T_PUR_POORDER ORDER BY FID OFFSET {0} ROWS FETCH NEXT {1} ROWS ONLY", offset, batchSize ); DataSet ds = DBUtils.ExecuteDataSet(ctx, sql); if (ds.Tables[0].Rows.Count == 0) break; foreach (DataRow row in ds.Tables[0].Rows) { allBillNos.Add(row["FBILLNO"].ToString()); } offset += batchSize; } } public void BatchUpdateInTransaction(List ids, string newStatus) { using (KDTransactionScope scope = new KDTransactionScope()) { foreach (long id in ids) { string sql = "UPDATE T_PUR_POORDER SET FSTATUS = @Status WHERE FID = @ID"; var parameters = new List { new SqlParam("@Status", KDDbType.AnsiString, newStatus), new SqlParam("@ID", KDDbType.Int64, id) }; DBUtils.Execute(ctx, sql, parameters); } scope.Complete(); } } }