Save a DataTable to SQL Server database and make the database table at the same time

Posted on 2007-10-15
Medium Priority
Last Modified: 2008-01-09
I have a DataTable object, filled with data from an existing query (used a DataAdaptor and SQL statement).

I want to put the data in this DataTable object into a new table in an SQL Server database.
How do I make the table and populate it as fast as possible from a C# application?
Question by:MTecho
LVL 13

Expert Comment

ID: 20083104
You can use SELECT INTO statement to input data to new table in SQL Server.
LVL 96

Accepted Solution

Bob Learned earned 150 total points
ID: 20084753
If you have an existing DataTable, and you don't have a target table, you could use SMO to create the target table, and then use SqlBulkCopy (if you have 2005) to quickly insert the records from the DataTable.


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Suggested Courses

862 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