locked
Importing excel into sql server using c# RRS feed

  • Question

  • how to import excel data into sql server using c# in web application
    Tuesday, March 20, 2012 7:48 PM

Answers

  • I have a general idea: Read Excel data to a datatable and then save the datatable to the SQL Server database.

     To read Excel data to a datatable in ASP.Net, Here is a similar issue for your reference:

        http://forums.asp.net/t/1255191.aspx/1 

     To save a datatable to SQL Server database, we can easily use SqlBulkCopy.WriteToServer method.

     Here is the document about it for your reference:

     http://msdn.microsoft.com/en-us/library/ex21zs8x.aspx 

     I just have a code  example.

      

    SqlBulkCopy bulkcopy = new SqlBulkCopy(myConnection); bulkcopy.DestinationTableName = table.TableName;

    bulkcopy.WriteToServer(table);

    And I also would suggest you to try to post it at ASP.Net forum for better support.
      Http://forums.asp.net

    Hope it helps.


    Best Regards,
    Rocky Yue[MSFT]
    MSDN Community Support | Feedback to us

    • Proposed as answer by FUCK QHRBanned Tuesday, March 27, 2012 1:41 AM
    • Marked as answer by Lie You Tuesday, March 27, 2012 2:58 AM
    Thursday, March 22, 2012 3:40 AM