本文介绍了Datatable.merge喜欢加入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有两个 DataTables 这样:DataTable dt1 = new DataTable();DataTable dt2 = new DataTable(); dt1 : dt2 : 我需要合并两个 DataTables 并设置为 GridView 如下所示:I need to merge two DataTables and set to GridView like this:dt1.Merge(dt2, true, MissingSchemaAction.Add);GridView1.DataSource = dt1;GridView1.DataBind();但是得到这样的输出: 如何合并这样? 推荐答案您需要添加以下行:dt1.PrimaryKey = new[] { dt1.Columns[0], dt1.Columns[1] };dt2.PrimaryKey = new[] { dt2.Columns[0], dt2.Columns[1] }; 这篇关于Datatable.merge喜欢加入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-01 13:35