首页 > 代码库 > SqlBulkCopy
SqlBulkCopy
private static void DataTableToSQLServer( DataTable dt) { string connectionString = GetConnectionString(); using (SqlConnection destinationConnection =new SqlConnection(connectionString)) { destinationConnection.Open(); using (SqlBulkCopy bulkCopy =new SqlBulkCopy(destinationConnection)) { try { bulkCopy.DestinationTableName = "T_EIInformation";//要插入的表的表明 bulkCopy.ColumnMappings.Add("Email", "Email");//映射字段名 DataTable列名 ,数据库 对应的列名 bulkCopy.ColumnMappings.Add("author", "author"); bulkCopy.ColumnMappings.Add("Title", "Title"); bulkCopy.ColumnMappings.Add("Type", "Type"); bulkCopy.ColumnMappings.Add("confName", "confName"); bulkCopy.ColumnMappings.Add("Language", "Language"); bulkCopy.ColumnMappings.Add("Publicationyear", "Publicationyear"); bulkCopy.ColumnMappings.Add("Conferencelocation", "Conferencelocation"); bulkCopy.WriteToServer(dt); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { // Close the SqlDataReader. The SqlBulkCopy // object is automatically closed at the end // of the using block. } } } }
SqlBulkCopy
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。