Insert record in Identity field of table using CommandBuilder
-
I have two datatable named lik dtSource(from Source Database) and dtDestination(from Destination database), I have to insert all record of dtSoruce in dtDestination using CommandBuilder. I am generation the query using commandbuilder daDestination.InsertCommand = commandBuilder.GetInsertCommand(); daDestination.Update(dtDestination); the above line of code insert all record successfully in destination table, But my proble is that i want to insert record in Identity field of destiantion table from dtSoruce. I am using sqlbulkcopy but it also not do. what is the process of inserting recording in identity field using commandbuilder???????????
-
I have two datatable named lik dtSource(from Source Database) and dtDestination(from Destination database), I have to insert all record of dtSoruce in dtDestination using CommandBuilder. I am generation the query using commandbuilder daDestination.InsertCommand = commandBuilder.GetInsertCommand(); daDestination.Update(dtDestination); the above line of code insert all record successfully in destination table, But my proble is that i want to insert record in Identity field of destiantion table from dtSoruce. I am using sqlbulkcopy but it also not do. what is the process of inserting recording in identity field using commandbuilder???????????
An identity field can not be set using insert. It will be auto-incremented by sql. If you want to intially set the values because you need to seed the table with pre-existing values, remove identity, insert values, then turn back on. On an on-going basis, if you want to control the values in the identity column, you will not want to have the field as an identity column at all. sqlbulkcopy does have an keepidentity option. http://msdn.microsoft.com/en-us/library/tchktcdk(VS.80).aspx[^] For performance reasons, I would handle the identity outside of the sqlbulkcopy process as well as other contraints and indexes. Depends on what, how often, how much...
modified on Thursday, March 25, 2010 9:27 AM