Saravanu
asked on
Copy DataTable Structure without Data
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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?
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
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
Hi Saravanu,
Can you tell me why B Grade?
Check this in the rules of EE : https://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP.NET/help.jsp#hi73
B..M
Can you tell me why B Grade?
Check this in the rules of EE : https://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP.NET/help.jsp#hi73
B..M
ASKER
please let me know how to change the grade
as a Dot.Net Page Editor i can unaccept the answer and you can change it
B..M
B..M
ASKER
pls do that
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.