首页 > 代码库 > SqlBulkCopy批量更新数据库表用例

SqlBulkCopy批量更新数据库表用例

 using (SqlBulkCopy sqlbulkcopy = new SqlBulkCopy(da.Connection as SqlConnection, SqlBulkCopyOptions.Default, tran as SqlTransaction))
                    {
                        sqlbulkcopy.BatchSize = entityList.Count;
                        sqlbulkcopy.DestinationTableName = TableName;
                        DataTable rightsTable = entityList.ToTable();
                        for (int i = 0; i < rightsTable.Columns.Count; i++)
                        {
                            sqlbulkcopy.ColumnMappings.Add(rightsTable.Columns[i].ColumnName, rightsTable.Columns[i].ColumnName);
                        }
                        sqlbulkcopy.WriteToServer(rightsTable);
                    }

SqlBulkCopy批量更新数据库表用例