- A+
所属分类:.NET技术
MySqlConnector有个MySqlBulkCopy批量新增数据方法,不过只能用DataTable,需要把list转成DataTable代码如下:
MySqlBulkCopy mySqlBulkCopy = new MySqlBulkCopy(conn) { DestinationTableName = "userinfo" }; mySqlBulkCopy.ColumnMappings.AddRange(table.Columns.Cast<DataColumn>().Select(colum => new MySqlBulkCopyColumnMapping { DestinationColumn = colum.ColumnName, SourceOrdinal = colum.Ordinal }).ToList()); mySqlBulkCopy.WriteToServer(table);