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

Posted on 2007-10-15
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

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

    Accepted Solution

    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

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
    Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
    Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
    Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now