如何将一个表中的数据按列插入到另一个表中 [英] how to insert data from one table to the other by column for the same item
问题描述
我有桌子A和B
A.
HoleNo - Depth_From - Depth_to
A1 - 12 - 14
A1 - 2 - 6
A1 3 - 5
A1 - 4 - 6
B 。
HoleNo - Depth_From - Depth_to
现在我想逐列插入表A中的数据,因此我想从表A插入数据通过插入所有孔编号然后插入depth_from然后deep_to而不对订单进行任何更改。
对我来说最困难的方面是不必对表A进行任何更改。
我试图插入和更新,但无法获得任何密钥使用。
我想用DATA TABLE
我怀疑你想要的是得到一个数据的排序视图,你相信你需要制作一个新表来实现它。
Dim dt As New DataTable
Dim r As DataRow
with dt
.Columns.Add(HoleN o,GetType(String))
.Columns.Add(Depth_From,GetType(Double))
.Columns.Add(Depth_To,GetType(Double))
r =。 NewRow:r(0)=A1:r(1)= 12:r(2)= 14:.Rows.Add(r)
r = .NewRow:r(0)=A1:r (1)= 2:r(2)= 6:.Rows.Add(r)
r = .NewRow:r(0)=A1:r(1)= 3:r(2)= 5 :.Rows.Add(r)
r = .NewRow:r(0)=A1:r(1)= 4:r(2)= 6:.Rows.Add(r)
.DefaultView.Sort =[HoleNo] ASC,[Depth_From] ASC,[Depth_To] ASC
以
结束dgv1.DataSource = dt.DefaultView
I have table A and B
A.
HoleNo - Depth_From - Depth_to
A1 - 12 - 14
A1 - 2 - 6
A1 3 - 5
A1 - 4 - 6
B.
HoleNo - Depth_From - Depth_to
Now I want to insert data from table A by column thus I want to insert data from table A by inserting all hole numbers then followed by depth_from then depth_to without making any changes to the order.
The most difficult aspect for me is that no changes must be made to table A.
I have tried to insert and update but cant get any key to use.
I would like to achieve this using DATA TABLE
I suspect that what you want is to get a sorted view of the data and you believe that you need to make a new table to achieve it.
Dim dt As New DataTable Dim r As DataRow With dt .Columns.Add("HoleNo", GetType(String)) .Columns.Add("Depth_From", GetType(Double)) .Columns.Add("Depth_To", GetType(Double)) r = .NewRow : r(0) = "A1" : r(1) = 12 : r(2) = 14 : .Rows.Add(r) r = .NewRow : r(0) = "A1" : r(1) = 2 : r(2) = 6 : .Rows.Add(r) r = .NewRow : r(0) = "A1" : r(1) = 3 : r(2) = 5 : .Rows.Add(r) r = .NewRow : r(0) = "A1" : r(1) = 4 : r(2) = 6 : .Rows.Add(r) .DefaultView.Sort = "[HoleNo] ASC, [Depth_From] ASC, [Depth_To] ASC" End With dgv1.DataSource = dt.DefaultView
这篇关于如何将一个表中的数据按列插入到另一个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!