Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Insert record in Identity field of table using CommandBuilder

Insert record in Identity field of table using CommandBuilder

Scheduled Pinned Locked Moved ASP.NET
databasequestionannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sudhanshu Mani Tripathi
    wrote on last edited by
    #1

    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???????????

    M 1 Reply Last reply
    0
    • S Sudhanshu Mani Tripathi

      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???????????

      M Offline
      M Offline
      Member 4501940
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups