Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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 4:04am
Edited 27-Feb-13 4:08am
v2
Comments
ThePhantomUpvoter at 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 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

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
      .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
  Permalink  
Comments
rosoftghana at 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 at 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 at 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)

  Print Answers RSS
0 OriginalGriff 358
1 Sergey Alexandrovich Kryukov 239
2 MT_ 175
3 Yogesh Kumar Tyagi 165
4 ChauhanAjay 156
0 Sergey Alexandrovich Kryukov 6,205
1 OriginalGriff 5,333
2 CPallini 2,473
3 Richard MacCutchan 1,617
4 Abhinav S 1,530


Advertise | Privacy | Mobile
Web03 | 2.8.140814.1 | Last Updated 27 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100