Creating a physical table through a data table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello people,

Is there a way to "save" an ADO DataTable in a physical database.
For example, i have an in memory DataTable that i created using ADO.Net
Methods and i want to create a physical table in the database with the same
attributes of my DataTable during run-time.

Thanks
Vanclei
 
If the table already exists (structurally) in the back end.

Set the AcceptChangesDuringFill property of your dataadapter to false, and
then Fill your datatable. Now, configure an adapter pointing to where you
need the data to go and call update. It will trasnfer it into the
destination table.

Otherwise, you're going to have to fire a DDL statement to create the table.
You can get the schema of the datatable object though and build your DDL
Statement from there.
 
Vanclei,

If you want to know if you can use the schema information of your own
created datatable to create a table with information in your database with
by instance one statement, than the answer is "No"

If you want to use that information than it is as much work as if you use
the information direct that you had used to create the table.

I hope this helps,

Cor
 
There is no one shot method.

There is a straightforward programmatic way to do this, i.e.

1. First create the table by using ExecuteNonQuery with a Create table
statement.
2. Then run a loop with another DbCommand (SqlCommand?) that acts row by
row.

The above approach might be terribly slow but is a fully managed solution.

Your other choice is to export the DataTable to XML and then use a SQL
Server import process.
This approach will be quicker, but it will be not fully managed. This will
also require you to first create the table.

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
 
Back
Top