Click here to Skip to main content
15,886,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 27-Feb-13 4:08am
v2
Comments
[no name] 27-Feb-13 10:09am    
Your question does not make any sense. What does the order in the database have to with anything? A simple INSERT statement is all you should need.
wizy@2020 28-Feb-13 2:57am    
this is what I actually want to achieve.
I have two tables as I have already shown.
Table A
HoleNo Depth_from Depth_to
A1 1 2
A1 3 4
A1 5 6

Table B
HoleNo Depth_from Depth_to
A1
A1
A1

Now How do I update table B so that it looks like table A
Note that no changes must be made to table A.

1 solution

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
 
Share this answer
 
Comments
wizy@2020 27-Feb-13 11:28am    
I understand your solution very well.
But I have to save all HoleNo in table B from Table A first and go back to Table A,pick values under Depth_from and come to update Table B in that order.
TnTinMn 27-Feb-13 12:22pm    
Not sure if I understand you correctly, but you can make an ordered copy based on my previous example with this.

Dim dt2 As DataTable = dt.Clone()
For Each dvr As DataRowView In dt.DefaultView
dt2.ImportRow(dvr.Row)
Next
wizy@2020 28-Feb-13 2:59am    
this is what I actually want to achieve.
I have two tables as I have already shown.
Table A
HoleNo Depth_from Depth_to
A1 1 2
A1 3 4
A1 5 6

Table B
HoleNo Depth_from Depth_to
A1
A1
A1

Now How do I update table B so that it looks like table A
Note that no changes must be made to table A.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900