13,256,123 members (30,760 online)
Rate this:
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 27-Feb-13 5:04am
Updated 27-Feb-13 5:08am
v2
ThePhantomUpvoter 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.
rosoftghana 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.

Rate this:

## Solution 1

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
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
```
rosoftghana 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
rosoftghana 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)

Top Experts
Last 24hrsThis month
 Dave Kreskowiak 185 F-ES Sitecore 135 OriginalGriff 120 Jochen Arndt 120 CPallini 95
 OriginalGriff 4,054 Karthik Bangalore 2,276 ppolymorphe 1,744 Dave Kreskowiak 1,551 CPallini 1,335

Advertise | Privacy |
Web03 | 2.8.171114.1 | Last Updated 27 Feb 2013