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 7988665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:31:28+00:00 2026-06-04T12:31:28+00:00

I am doing a bulk insert: // Get the data into the DataTable //dtData

  • 0

I am doing a bulk insert:

// Get the data into the DataTable
//dtData = GetData(...);

// Create an object of SqlBulkCopy
SqlBulkCopy objSBC = new SqlBulkCopy(connection);
// Specify the destination table
objSBC.BulkCopyTimeout = 0;
objSBC.BatchSize = 10000;
objSBC.DestinationTableName = "QuickLabDump";
// Write the data to the SQL Server

objSBC.WriteToServer(QuickLabDump);

my datatable that i am inserting looks like this:

QuickLabDump = new DataTable();

QuickLabDump.Columns.Add("Time Collected", typeof(TimeSpan));
QuickLabDump.Columns.Add("Time Entered", typeof(TimeSpan));
QuickLabDump.Columns.Add("Time Completed", typeof(TimeSpan));
QuickLabDump.Columns.Add("Test Time", typeof(TimeSpan));

QuickLabDump.Columns.Add("Date Collected", typeof(DateTime));
QuickLabDump.Columns.Add("Date Entered", typeof(DateTime));
QuickLabDump.Columns.Add("Date Completed", typeof(DateTime));
QuickLabDump.Columns.Add("Test Date", typeof(DateTime));
......

When I run the bulk insert from c# (code above), I am getting the following error:

The given value of type DateTime from the data source cannot be converted to type time of the specified target column.

I think the problem is that I am inserting typeof(DateTime) into a sql server 2008 table that is time(0)

Here’s a sample of the data that I am inserting:

6:50:00 AM
6:50:00 AM
6:50:00 AM
10:36:00 AM
4:45:00 PM
7:39:00 PM

Question: how do I define a datatable column properly so that it will insert the above time values into a time(0) column?

Here are values that already exist in the database table in the time(0) fields:

14:57:00
14:58:00
14:58:00
14:57:00
10:49:00
13:31:00
14:02:00
14:13:00
14:20:00
14:56:00
15:00:00

This is how I am adding data into DataTable:

 public DataTable dt;
        public ReadFileIntoDataTable(string inputfile)
        {
            using (GenericParserAdapter parser = new GenericParserAdapter())
            {
                parser.SetDataSource(inputfile);

                char[] delimiters = new char[] { ',' };
                parser.ColumnDelimiter = delimiters[0];
                parser.FirstRowHasHeader = true;
                //parser.SkipDataRows = 10;
                parser.MaxBufferSize = 4096;
                //parser.MaxRows = 500;
                parser.TextQualifier = '\"';

                dt = parser.GetDataTable();   


            }
  • 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-06-04T12:31:30+00:00Added an answer on June 4, 2026 at 12:31 pm

    i created explicit column mappings between my datatable and the sql server table:

    objSBC.ColumnMappings.Add(new SqlBulkCopyColumnMapping("datatable column name","sql server column name"));
    

    for all columns…..
    and that did the trick!!!

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

Sidebar

Related Questions

I'm doing a bulk insert of a CSV file into SQL Server 2005, using
I am doing a bulk insert of records into a database from a log
I’m trying to bulk insert data to SQL server express database. When doing bcp
I'm doing a bulk insert from a fixed width text file using INSERT INTO
I'm doing a bulk insert but before inserting into the actual table I need
I am doing a BULK INSERT into sqlserver and it is not inserting UTF-8
I'm doing a BULK INSERT into a table using a FMT format file, but
There are existing options for doing bulk insert into a single table with EF
I'm trying to do a huge bulk insert into an SqlCe database (version 3.5,
I'm doing some tests with nhibernate and I'm modifying batch_size to get bulk inserts.

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.