columnmappings

How to add 'Real' type to a DataTable?

ⅰ亾dé卋堺 提交于 2020-06-01 07:36:07
问题 I am bulkcopying records from a csv file to a sql table. The sql table has columns that are varchar, and columns that are real datatype (based on the csv attributes we are given) Lets suppose that the first 7 columns are the Foreign Keys of varchar(100), and the rest of the 80+ columns are Real datatype. During the bulk copy, I used Out-DataTable function because apparently thats the most efficient way to bulk copy (especially with our files containing 1000's of records). However, I am

How to use SqlBulkCopyColumnMappingCollection?

烈酒焚心 提交于 2019-12-17 18:53:09
问题 I want to make one SqlBulkCopy method that I can use for all my bulk inserts by passing in specific data through the parameters. Now I need to do mapping on some of them. I don't know how to make a SqlBulkCopyColumnMappingCollection since that was my plan to pass in the mapping collection in and use it. However I don't know how to make it. I can't make a new object of it. This is what I have now. How can I add it do mapping put pass it in? public void BatchBulkCopy(DataTable dataTable, string

Skip some columns in SqlBulkCopy

做~自己de王妃 提交于 2019-12-13 11:42:12
问题 I'm using SqlBulkCopy against two SQL Server 2008 with different sets of columns (going to move some data from prod server to dev ). So want to skip some columns not yet existed / not yet removed. How can I do that? Some trick with ColumnMappings ? Edit: I do next: DataTable table = new DataTable(); using (var adapter = new SqlDataAdapter(sourceCommand)) { adapter.Fill(table); } table.Columns .OfType<DataColumn>() .ForEach(c => bulk.ColumnMappings.Add( new SqlBulkCopyColumnMapping(c

How to differentiate duplicate column names from different source tables/subqueries by alias in an SQL select statement when using SqlDataReader?

核能气质少年 提交于 2019-12-11 14:01:56
问题 Suppose I have POCO entities being read from a database and they each have "ID" as their primary key column name. If selecting from more than one table or subquery with aliases a and b like select a.*, b.* from a, b , then the selected columns will include two ID columns (a.ID and b.ID), but the source table/subquery aliases are lost. I want to know if there's a way to preserve or dynamically obtain such a top-level alias for the source of the output columns of an arbitrary select query. I

How to use SqlBulkCopyColumnMappingCollection?

青春壹個敷衍的年華 提交于 2019-11-29 03:45:47
I want to make one SqlBulkCopy method that I can use for all my bulk inserts by passing in specific data through the parameters. Now I need to do mapping on some of them. I don't know how to make a SqlBulkCopyColumnMappingCollection since that was my plan to pass in the mapping collection in and use it. However I don't know how to make it. I can't make a new object of it. This is what I have now. How can I add it do mapping put pass it in? public void BatchBulkCopy(DataTable dataTable, string DestinationTbl, int batchSize) { // Get the DataTable DataTable dtInsertRows = dataTable; using