DataTable Import Database

Source: Internet
Author: User

public class Sqlbulk {public static void inserttable (DataTable dt, String tabelname, DataColumnCollection dtcolum)            {string Str= "";//Database connection string SqlConnection connn=new SqlConnection (str); Conn.          Open (); Declare SqlBulkCopy, using release unmanaged resource using (SqlBulkCopy SQLBC = new SqlBulkCopy (conn)) {//A                The amount of data inserted in the second batch sqlbc.batchsize = 1000;                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 table sqlbc.bulkcopytimeout = 60;                 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 bulk sqlbc.destinationtablename =tabelname;                Customize the DataTable and database fields to correspond to the//sqlbc.columnmappings.add ("id", "tel");                SQLBC.COLUMNMAPPINGS.ADD ("name", "Neirong"); for (int i = 0; i < Dtcolum.count; i++) {sqlBC.ColumnMappings.Add (Dtcolum[i]. Columnname.tostring (), Dtcolum[i].                Columnname.tostring ());            }//Bulk write sqlbc.writetoserver (DT); } conn.        Dispose (); }//Response time Event void Onsqlrowscopied (object sender, Sqlrowscopiedeventargs e) {//Response.writ        E ("<br/> ok!");     }    }

  

DataTable Import Database

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.