SqlBulkCopy: Add identity/counter column without ColumnMapping?


i'm reading data excel files , i'm using sqlbulkcopy read tsql tables. need read several excel files different formats , fields, don't use column mappings.

i'm using following code, working correctly. need add column have identity value. there easy way automatically add identity column without having map columns?

need rows numbered can identify , clean table more easily. example, know rows 8-12 can deleted table, can delete rows based on counter/identity column.

thanks.

string connectionstring = getconnectionstring();  using (sqlconnection connection = new sqlconnection(connectionstring))  {      sqlbulkcopy bulkcopy =          new sqlbulkcopy          (          connection,          sqlbulkcopyoptions.tablelock |          sqlbulkcopyoptions.firetriggers |          sqlbulkcopyoptions.useinternaltransaction,          null          );        bulkcopy.destinationtablename = tablename;      connection.open();        bulkcopy.writetoserver(table);      connection.close();  }

vm

i ended adding identity column table:

alter table table
add id int identity(1,1)


vm



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'