Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copying DataColumns from one DataTable to another

Status
Not open for further replies.

jesal27

Programmer
Mar 4, 2004
7
US
hi,

can anyone tell me how to do the following

e.g. code

datatable dt1,dt2

dt1.columns.add(dt2.columns.item(0))

basically how do i copy a datacolumn from one datatable to another.

when i use the above code..it throws an error that the column already belongs to another datatable

i appreciate any input.

thx
jes
 
Create a new DataColumn instance first
Code:
Dim newdc As New DataColumn
newdc = dt1.Columns(0)
dt2.Columns.Add(newdc)



Sweep
...if it works dont mess with it
 
hi,

thnks for the reply..

unfortunately that wont work either, the same error will pop up the moment u say .add(somewNewColumn) if u write
someNewColumn=someDataTable.Columns(0)

but i figured a way out yesterday..

just in case u wanna know..heres what i did..

i made a newColumn

i then actually populated the entire column by traversing each row in the other dataTable

and then i added this column to the dataTable1

im yet to figure out why i needed to do this..

but i appreciate ur input..

thx.

p.s.. are you good at vb.net/ado.net??coz im workign on this new project..and sometimes i get stuck ..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top