MVC Load data from Excel to SQLServer

后端 未结 2 1258
清歌不尽
清歌不尽 2021-01-27 08:16

I have a code that loads data from Excel into SQLServer table. It works fine, but I need to know if there\'s a best way to do it, I mean do the process faster. This is because i

相关标签:
2条回答
  • 2021-01-27 08:43

    You can use either an Excel or SQL Server reference in-line on an Excel or SQl Server connection, for example:

    SELECT Col1, Col2, Col3 INTO 
    [ODBC;Description=TEST;DRIVER=SQL Server;SERVER=Some\Instance;Trusted_Connection=Yes;DATABASE=test].TableZ  FROM [Sheet1$]"
    

    You will probably need to enable ad hoc queries on SQL Server and if you are using ACE there may be some other considerations:

    SELECT * INTO newx
    FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
        'Excel 8.0;HDR=YES;IMEX=1;Database=c:\docs\testdata.xls',
        'SELECT * FROM [Sheet2$]');
    
    0 讨论(0)
  • 2021-01-27 08:54

    I cretaed a package using SSIS. This is a good solutions and from code I send parameters to Package (Package.dtsx)

    The bulk load is reduced amazingly :)

    0 讨论(0)
提交回复
热议问题