Excel bulk-guided data to SQL Server

Source: Internet
Author: User

         string filepath = @ "D:\data.xlsx";           string strConn =  "provider= microsoft.ace.oledb.12.0; persist security info=false; "  +  "Data source="  +                            filepath  +  "; extended properties= ' excel 12.0; hdr=yes; imex=2 ' ";           OleDbConnection con = new   OleDbConnection (strconn);           string excelsql =  "select    * from [data$] ";           OleDbDataAdapter da = new  OleDbDataAdapter (Excelsql, con);           daTaset ds = new dataset ();           da.  Fill (DS);           console.writeline (ds. Tables.count);           console.writeline (ds. Tables[0]. Rows.Count);           string conStr =               "server=.;  Database=test;uid=sa;pwd=123 ";           stopwatch wt=new stopwatch ();           WT.   Start ();           using  (sqlbulkcopy bulkcopy =  New sqlbulkcopy (CONSTR))           {               bulkcopy.destinationtablename =  "_mobile";               //joins only one column, Then other repositories are implicitly empty.                 BULKCOPY.COLUMNMAPPINGS.ADD ("mobile",  "mobile");               bulkcopy.bulkcopytimeout  = 60 * 20;               bulkcopy.batchsize =  100;               bulkCopy.NotifyAfter  = 100;               bulkcopy.writetoserver (ds. Tables[0]);           }           WT. Stop ();           console.writeliNE ("time:>>" +WT. elapsedmilliseconds/1000+ "S");

Excel bulk data to SQL Server

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.