[VB.NET]vb.net中如何将两个结构不同的DATATABLE合并成一个DATATABLE

前端之家收集整理的这篇文章主要介绍了[VB.NET]vb.net中如何将两个结构不同的DATATABLE合并成一个DATATABLE前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
vb.net中如何将两个结构不同的DATATABLE合并成一个DATATABLE vb.net中如何将两个结构不同的DATATABLE合并成一个DATATABLE __________________________________________________________________________ Public Class Form1 Private Sub Form1_Load(ByVal sender As Object,ByVal e As System.EventArgs) Handles Me.Load 合并2个DT Dim dt1 As New DataTable Dim dt2 As New DataTable Dim dt3 As DataTable = dt1.Clone() For i As Int32 = 0 To dt2.Columns.Count - 1 dt3.Columns.Add(dt2.Columns(i).ColumnName) Next Dim obj As New Object obj = dt3.Columns.Count For i As Int32 = 0 To dt1.Rows.Count - 1 dt1.Rows(i).ItemArray.CopyTo(obj,0) dt3.Rows.Add(obj) Next If (dt1.Rows.Count > = dt2.Rows.Count) Then For i As Int32 = 0 To dt2.Rows.Count - 1 For j As Int32 = 0 To dt2.Columns.Count - 1 dt3.Rows(i)(j + dt1.Columns.Count) = dt2.Rows(i)(j).ToString() Next Next Else Dim dr3 As DataRow For i As Int32 = 0 To dt2.Rows.Count - dt1.Rows.Count - 1 dr3 = dt3.NewRow() dt3.Rows.Add(dr3) Next For i As Int32 = 0 To dt2.Rows.Count - 1 For j As Int32 = 0 To dt2.Columns.Count - 1 dt3.Rows(i)(j + dt1.Columns.Count) = dt2.Rows(i)(j).ToString() Next Next End If End Sub End Class __________________________________________________________________________ 由wf5360308(王峰)的C#程序修改得来。 __________________________________________________________________________ 原文链接:https://www.f2er.com/vb/263717.html

猜你在找的VB相关文章