private void BuildScriptWithDataTable(Table table, IDataWrapper data, IDataFilter filter, out object script) { // 创建数据表,字段清单与目标表须一致 DataTable dt = new DataTable(); for (int i = 0; i < table.DestFields.Length; i++) { dt.Columns.Add(table.DestFields[i], data.GetFieldType(i)); } // 给跳过字段名称增加一个前缀,这样字段映射后取值就为 NULL string[] fields = ModifyFields(table.DestFields, table.SkipFields, "!!!"); data.MapFields(fields); // 添加第一笔记录,仍然使用正确的字段名 DataRow row = dt.NewRow(); for (int i = 0; i < table.DestFields.Length; i++) { row[i] = filter.GetValue(data, i, table.DestFields[i]); } dt.Rows.Add(row); // 添加后续记录,仍然使用正确的字段名 int r = 1; while (r < table.PageSize && data.Read()) { row = dt.NewRow(); for (int i = 0; i < table.DestFields.Length; i++) { row[i] = filter.GetValue(data, i, table.DestFields[i]); } dt.Rows.Add(row); r++; } script = new AppendScript() { Data = dt, KeepIdentity = table.KeepIdentity }; }