By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,588 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

Copy table schema

P: n/a
Hi:

What is the best way to copy the schema of one DataTable to another ?,
The DataTable.Clone will create a new DataTable

Currently i do it manually

destTable.Clear()
destTable.Columns.Clear()
destTable.Constraints.Clear()

For Each dcSrc In srcTable.Columns
dcDest = destTable.Columns.Add()

dcDest.AllowDBNull = dcSrc.AllowDBNull
dcDest.AutoIncrementStep = dcSrc.AutoIncrementStep
dcDest.AutoIncrementSeed = dcSrc.AutoIncrementSeed
dcDest.AutoIncrementStep = dcSrc.AutoIncrementStep
dcDest.Caption = dcSrc.Caption
dcDest.ColumnMapping = dcSrc.ColumnMapping
dcDest.ColumnName = dcSrc.ColumnName
dcDest.DataType = dcSrc.DataType
dcDest.DefaultValue = dcSrc.DefaultValue
dcDest.Expression = dcSrc.Expression
dcDest.MaxLength = dcSrc.MaxLength
dcDest.Namespace = dcSrc.Namespace
dcDest.Prefix = dcSrc.Prefix
dcDest.ReadOnly = dcSrc.ReadOnly
dcDest.Unique = dcSrc.Unique
Next

There must be an easy way to achieve this, any idea ?

JCVoon
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

Table.clone is the best way to copy the Schema of One table into another...............

actually ur quest. is not clear can u explin in detail.what exactly u wan a do?

--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #2

P: n/a
Ritesh Jain
Table.clone is the best way to copy the Schema of One table into another...............
actually ur quest. is not clear can u explin in detail.what exactly u wan a do?


Thanks for the info. Here is what i'm trying to do

public sub Caller()
' For some reason i've to create the dt before call MyFunction
dim dt as DataTable = new DataTable
...
MyFunction(dt)
...--------> after the call the dt remain empty (Columns count=0)
end sub
public sub MyFunction(dtDest as DataTable)
dim dtSrc as DataTable
...
dtDest = dtSrc.Clone
...
end sub
In the debuger i can see the dtDest schema, but after return to the
caller the schema gone ! I don't know why
Any idea ?

Thanks
JCVoon


Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.