实现功能的核心代码
SqlConnection destinationConnection = new SqlConnection(connectionString);
destinationConnection.Open();
SqlBulkCopy bulkCopy = new SqlBulkCopy(destinationConnection);
bulkCopy.DestinationTableName = "checkinout";//要插入的表的表名
bulkCopy.BulkCopyTimeout = 600; bulkCopy.BatchSize = dt.Rows.Count; bulkCopy.ColumnMappings.Add("ID", "ID");//映射字段名 DataTable列名 ,数据库 对应的列名 bulkCopy.ColumnMappings.Add("TIME", "TIME"); bulkCopy.WriteToServer(dt);