Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6979429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:53:10+00:00 2026-05-27T17:53:10+00:00

i have two datatables that i am inserting into sql server 2008 using SqlBulkCopy

  • 0

i have two datatables that i am inserting into sql server 2008 using SqlBulkCopy

here they are:

      QuickLabDump = new DataTable();
            QuickLabDump.Columns.Add("Specimen ID", typeof(string));
            QuickLabDump.Columns.Add("Client Key", typeof(int));
            QuickLabDump.Columns.Add("Outcome", typeof(string));
            QuickLabDump.Columns.Add("Medications", typeof(string));
            QuickLabDump.Columns.Add("Date Collected", typeof(DateTime));
            QuickLabDump.Columns.Add("Time Collected", typeof(TimeSpan));
            QuickLabDump.Columns.Add("Date Entered", typeof(DateTime));
            QuickLabDump.Columns.Add("Time Entered", typeof(TimeSpan));
            QuickLabDump.Columns.Add("Date Completed", typeof(DateTime));
            QuickLabDump.Columns.Add("Time Completed", typeof(TimeSpan));
            QuickLabDump.Columns.Add("Test Date", typeof(DateTime));
            QuickLabDump.Columns.Add("Test Time", typeof(TimeSpan));
            QuickLabDump.Columns.Add("Practice Name", typeof(string));
            QuickLabDump.Columns.Add("Practice Code", typeof(string));
            QuickLabDump.Columns.Add("Client ID", typeof(string));
            QuickLabDump.Columns.Add("Requesting Physician", typeof(string));
            QuickLabDump.Columns.Add("Other Medications", typeof(string));
            QuickLabDump.Columns.Add("Order Comments", typeof(string));
            QuickLabDump.Columns.Add("Reference Number", typeof(string));
            QuickLabDump.Columns.Add("Order Count", typeof(int));    

            TestResults = new DataTable();
            TestResults.Columns.Add("TestName", typeof(String));
            TestResults.Columns.Add("Result", typeof(Decimal));
            TestResults.Columns.Add("NonNumericResult", typeof(String));
            TestResults.Columns.Add("QuickLabDumpid", typeof(int));

on the database they are:

[Specimen ID] [varchar](50) NOT NULL,
    [Client Key] [int] NOT NULL,
    [Outcome] [varchar](50) NOT NULL,
    [Medications] [varchar](max) NULL,
    [Date Collected] [date] NOT NULL,
    [Time Collected] [time](0) NOT NULL,
    [Date Entered] [date] NOT NULL,
    [Time Entered] [time](0) NOT NULL,
    [Date Completed] [date] NOT NULL,
    [Time Completed] [time](0) NOT NULL,
    [Test Date] [date] NULL,
    [Test Time] [time](0) NULL,
    [Practice Name] [varchar](500) NOT NULL,
    [Practice Code] [varchar](500) NOT NULL,
    [Client ID] [varchar](500) NULL,
    [Requesting Physician] [varchar](500) NULL,
    [Other Medications] [varchar](max) NULL,
    [Order Comments] [varchar](max) NULL,
    [Reference Number] [varchar](500) NULL,
    [Order Count] [int] NOT NULL,
    [QuickLabDumpID] [int] IDENTITY(1,1) NOT NULL,

and

[TestName] [varchar](500) NOT NULL,
    [Result] [decimal](18, 4) NULL,
    [NonNumericResult] [varchar](100) NULL,
    [QuickLabDumpID] [int] NOT NULL,
    [TestResultsID] [int] IDENTITY(1,1) NOT NULL,

[QuickLabDumpID] [int] IDENTITY(1,1) NOT NULL this one is autoincrement. each time a row is inserted it increments. it is also a foreign key for the same column on the other table.

question i have no problem inserting records into either table; however, i need to preserve the referential integrity so that the QuickLabDumpID on the first table matches the QuickLabDumpID on the other table.

i do NOT want to use @@identity because i am inserting 100million rows and this will take days!! i have tried it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:53:11+00:00Added an answer on May 27, 2026 at 5:53 pm

    I think that your best option is to SET IDENTITY_INSERT QuickLabDump ON before the bulk copy and then turn it off afterwards.

    You will then need to generate ids for each of the rows to be inserted unless they are already present in the incoming data set.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two Databases. They are both filled into DataTables using the GetTable1 \
I have a web application that loads some 50 tables from SQL Server into
I have the following code that fills dataTable1 and dataTable2 with two simple SQL
I have two DataTables. First is DataTable NameAddressPhones = new DataTable(); with Three columns
I have two datatables dt1 and dt2 i copied dt2 into dt1 and clear
Okay, here is my problem: I have a form that requires to have two
I have a .NET application that is merging two datatables with a lot of
I have a very simple linq query that gets data from two datatables (orderHeader
I have two DataTables, A and B , produced from CSV files. I need
I have two datatables. One is to display names. Another contains three <h:selectOneMenu> .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.