Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Copy DataTable Structure without Data

Posted on 2004-08-05
9
Medium Priority
?
3,437 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
9 Comments
 
LVL 28

Accepted Solution

by:
mmarinov earned 200 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Loops Section Overview

610 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