Solved

Copy DataTable Structure without Data

Posted on 2004-08-05
9
3,431 Views
Last Modified: 2008-06-21
I have a one datatable dt1 with some data

I need to create a new datatable dt2 and I shud copy the structure of dt1 without copying data.

is it possible ?

I know it is possible to copy both data and structure using copy method





0
Comment
Question by:Saravanu
  • 4
  • 3
9 Comments
 
LVL 28

Accepted Solution

by:
mmarinov earned 50 total points
ID: 11725173
Hi,

there is a method called Clone() that do exactly what you want

Regards,
B..M
0
 
LVL 14

Expert Comment

by:puranik_p
ID: 11725335
Let me get it right.

You have a table in your database and you need to create exact copy of that , but not the data. A one time job. right ?

If yes,

SELECT TOP 0 * INTO <NewTableName> FROM <ExistingTableName>

This will work with MS SQL Server and Access.
0
 

Author Comment

by:Saravanu
ID: 11725435
B..M

No way denying  points u deserve

but when I refer .Clone I get NullException error , y is that..

I have a dataTable which has been set in Page_Load (!isPostBack)

I am using that dataset now in a button click event.

when I refer that dataTable.Clone am getting nullexception error.

how to solve this?



0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 28

Expert Comment

by:mmarinov
ID: 11725576
the syntax for using Clone method is

DataTable dt = _srouceDataTable.Clone();

in your case may be the datatable object is null in the button's click event.
you have to trace(debug) your application and check where the datatable became null

Regards,
B..M
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 11733147
Hi Saravanu,

Can you tell me why B Grade?
Check this in the rules of EE : http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP.NET/help.jsp#hi73

B..M
0
 

Author Comment

by:Saravanu
ID: 11733158
please let me know how to change the grade
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 11733174
as a Dot.Net Page Editor i can unaccept the answer and you can change it

B..M
0
 

Author Comment

by:Saravanu
ID: 11733184
pls do that
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question