?
Solved

Copy DataTable Structure without Data

Posted on 2004-08-05
9
Medium Priority
?
3,435 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

764 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