none
Pass DataTable object to DataAdapter INSERT method?? RRS feed

  • Question

  •  

    Hello all,

     

    I need to be able to populate a SQL data table with data contained within a DataTable object.

     

    Both table schemas are exactly the same, so I was wondering if anyone know of a way to pass the DataTable object to a DataAdapter INSERT method??

     

    Cheers,

    Sean 

    Tuesday, February 5, 2008 9:35 AM

Answers

  • If you need to transfer data from DataTable to SQL Server table then there are several ways to do this:

     

    1. You could use SqlDataAdapter, which will insert/update records one by one. Here are some samples how to work with SqlDataAdapter

     

    http://support.microsoft.com/kb/308507/en-us

     

    2. There also several bulk insert/update techniques you could use from inside of your application

     

    http://support.microsoft.com/kb/316244/en-us

     

     and in a case if you are using .NET 2.0 or newer, you could use SqlBulkCopy class, which allows transferring data directly from DataTable into SQL Server table and it works fast

     

    Tuesday, February 5, 2008 10:27 AM
    Moderator
  • Thanks very much, exactly what I needed.

     

    Tuesday, February 5, 2008 10:42 AM

All replies

  • If you need to transfer data from DataTable to SQL Server table then there are several ways to do this:

     

    1. You could use SqlDataAdapter, which will insert/update records one by one. Here are some samples how to work with SqlDataAdapter

     

    http://support.microsoft.com/kb/308507/en-us

     

    2. There also several bulk insert/update techniques you could use from inside of your application

     

    http://support.microsoft.com/kb/316244/en-us

     

     and in a case if you are using .NET 2.0 or newer, you could use SqlBulkCopy class, which allows transferring data directly from DataTable into SQL Server table and it works fast

     

    Tuesday, February 5, 2008 10:27 AM
    Moderator
  • Thanks very much, exactly what I needed.

     

    Tuesday, February 5, 2008 10:42 AM