1. Set up a test table testing
CREATE TABLE Test (f_name NVARCHAR () null, f_age INT null) 2, SqlBulkCopy BULK INSERT Data
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Text;4 usingSystem.Data.SqlClient;5 usingSystem.Data;6 7 namespaceSqlBulkCopy8 {9 class ProgramTen { One Static voidMain (string[] args) A { -DataTable dt =NewDataTable (); -Dt. Columns.Add ("name",typeof(string)); theDt. Columns.Add (" Age",typeof(int)); - -DataRow dr =dt. NewRow (); -dr["name"] ="Li thought"; +dr[" Age"] = -; - dt. Rows.Add (DR); + ADr =dt. NewRow (); atdr["name"] ="Chen Qi"; -dr[" Age"] = -; - dt. Rows.Add (DR); - - using(System.Data.SqlClient.SqlConnection conn =NewSystem.Data.SqlClient.SqlConnection ("Database connection String")) - { in Conn. Open (); - using(System.Data.SqlClient.SqlBulkCopy bulk =NewSystem.Data.SqlClient.SqlBulkCopy (conn)) to { +Bulk. DestinationTableName ="Test";//the name of the data table to import -Bulk. batchsize = dt. Rows.Count;//number of rows in each batch theBulk. Columnmappings.add ("name","F_name");//To set the mapping between columns in the data source and columns in the target table *Bulk. Columnmappings.add (" Age","F_age"); $ Bulk. WriteToServer (DT);Panax Notoginseng if(Bulk! =NULL) - { the Bulk. Close (); + } A } the Conn. Close (); + } - } $ } $}