MySqlConnector有個MySqlBulkCopy批量新增數據方法,不過只能用DataTable,需要把list轉成DataTable代碼如下: MySqlBulkCopy mySqlBulkCopy = new MySqlBulkCopy(conn) { DestinationTableN ...
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);