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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:51:46+00:00 2026-05-13T09:51:46+00:00

I got the following error when executing bulkcopy. System.InvalidOperationException The given value of type

  • 0

I got the following error when executing bulkcopy.

System.InvalidOperationException
The given value of type String from the data source cannot be converted to 
type decimal of the specified target column.

I use the following code.

DataTable empTable = DataTemplate.GetEmployees();
    DataRow row;
    for (int i = 0; i < gv.Rows.Count;i++ )
    {
        row = empTable.NewRow();
        string empName = gv.DataKeys[i].Values[0].ToString(); //first key
        string hourSalary = gv.DataKeys[i].Values[1].ToString(); //second key
        row["Emp_Name"] = empName;
        row["Hour_Salary"] = Convert.ToDecimal(hourSalary);
        row["Advance_amount"] = Convert.ToDecimal(0);
        row["Created_Date"] = Convert.ToDateTime(System.DateTime.Now.ToString());
        row["Created_By"] = Convert.ToInt64(1);
        row["Is_Deleted"] = Convert.ToInt64(0);
        empTable.Rows.Add(row);
    }
    InsertintoEmployees(empTable, "Employee");

My SQL datatypes for the above fields are:

Emp_Name nvarchar(50) ,
Hour_Salary numeric(18, 2), 
Advance_amount numeric(18, 2), 
Created_Date datetime,
Created_By numeric(18, 0), 
Is_Deleted numeric(18, 0) 

I don’t know what I am doing wrong.

  • 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-13T09:51:46+00:00Added an answer on May 13, 2026 at 9:51 am

    Your hourSalary variable is a string that you later try to convert to a Decimal and this fails.

    Most probably you have either an empty string value or an invalid value.

    Depending on your requirements you must decide what to do with the invalid value. You basically have two options except failing: Store as a default value (0 maybe?) or store as a Null value.

    If you want to store a default value then you can try the following when converting the salary:

    string hourSalary = gv.DataKeys[i].Values[1].ToString();
    double salary = 0;
    if (!double.TryParse(hourSalary, out salary))
    {
      salary = 0; // Set your default value here
    }
    row["Hour_Salary"] = salary;
    

    This will ensure that you get a valid decimal value stored in your Hour_Salary column.

    If you want to store a null value then you must change the code somewhat:

    string hourSalary = gv.DataKeys[i].Values[1].ToString();
    double salary;
    object salaryValue;
    if (double.TryParse(hourSalary, out salary))
    {
       salaryValue = salary;
    }
    else
    {
      salaryValue = DBNull.Value; // Store as a null
    }
    row["Hour_Salary"] = salaryValue;
    

    In this example we do the same TryParse, but if it fails we store DBNull.Value instead of the default 0 value.

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

Sidebar

Related Questions

I got the following error while trying to alter a column's data type and
I got following error... System.NullReferenceException: Object reference not set to an instance of an
I got the following error: Error 2 Value restriction. The value 'gbmLikelihood' has been
I got the following error of Oracle, ORA-25226: dequeue failed, queue string.string is not
I got the following error when executing an unmanaged assembly: Could not load file
I got the following output with error message while executing the program that uses
I am executing the following query and got the error Subquery returns more than
I tried installing TurboGears 1.0 on Windows 7 using tgsetup.py. and got following error
I got the following error while running my perl script with the negative lookaround
On a server running a Qt application I got the following error, as soon

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.