DataTable Import SQL SERVER Database

Source: Internet
Author: User

         Public voidInserttable (DataTable DT,stringTabelname, DataColumnCollection dtcolum) {            //string str = configurationmanager.connectionstrings["ConnectionString"].            Connectionstring.tostring (); //declaring a database connectionSqlConnection conn =NewSqlConnection (strconn); Conn.            Open (); //declaring SqlBulkCopy, using release of unmanaged Resources            using(SqlBulkCopy SQLBC =NewSqlBulkCopy (conn)) {                //Volume of data inserted at one timeSqlbc.batchsize = +; //The number of seconds allowed before the operation completes before timing out, if the transaction is not committed, the data is rolled back, and all replicated rows are removed from the target tableSqlbc.bulkcopytimeout = -; //set the Notifyafter property so that the corresponding event is called when each 10,000 data is inserted. Sqlbc.notifyafter =10000; //sqlbc.sqlrowscopied + = new Sqlrowscopiedeventhandler (onsqlrowscopied); //set the table to be written in bulkSqlbc.destinationtablename =Tabelname; //Customize the DataTable and database fields to correspond//SQLBC.COLUMNMAPPINGS.ADD ("id", "tel"); //sqlBC.ColumnMappings.Add ("name", "Neirong");                 for(inti =0; i < Dtcolum.count; i++) {sqlBC.ColumnMappings.Add (Dtcolum[i]. Columnname.tostring (), Dtcolum[i].                Columnname.tostring ()); }                //Bulk Writesqlbc.writetoserver (DT); } conn.        Dispose (); }        //Response-Time Events        voidOnsqlrowscopied (Objectsender, Sqlrowscopiedeventargs e) {            //Response.Write ("<br/> ok!");}

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.