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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:04:47+00:00 2026-06-09T23:04:47+00:00

Im importing a csv to my sql server table using the following code SqlCommand

  • 0

Im importing a csv to my sql server table using the following code

SqlCommand nonqueryCommand = myConnection.CreateCommand();
nonqueryCommand.CommandText = 
                 "INSERT INTO MYTABLE VALUES(@num1, @num2,@num3,@num4)";

nonqueryCommand.Parameters.Add("@num1",SqlDbType.Decimal);
nonqueryCommand.Parameters.Add("@num2", SqlDbType.Decimal);
nonqueryCommand.Parameters.Add("@num3", SqlDbType.Decimal);
nonqueryCommand.Parameters.Add("@num4", SqlDbType.Decimal);

nonqueryCommand.Parameters["@num1"].Value = crntRecord[0];
nonqueryCommand.Parameters["@num2"].Value = crntRecord[1];
nonqueryCommand.Parameters["@num3"].Value =crntRecord[3];
nonqueryCommand.Parameters["@num4"].Value = crntRecord[4];

nonqueryCommand.ExecuteNonQuery();

where the parameter 3 and 4 are of type decimal(9,6) in the DDL when i execute the code at ExecuteNonQuery i get the following exception

Failed to convert parameter value from a String to a Decimal.

please help me find out the problem tnx.

EDIT

the value in the crntRecord[3] looks like

enter image description here

  • 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-09T23:04:49+00:00Added an answer on June 9, 2026 at 11:04 pm

    Assuming that crntRecord is an array of strings, you need to parse the strings to a decimal first.

    Ex:

    nonqueryCommand.Parameters["@num3"].Value = decimal.Parse(crntRecord[3].ToString());
    

    Note that this will throw an exception if crntRecord[3] is not parseable to a decimal; if that’s a situation that could occur, look into decimal.TryParse() instead.

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

Sidebar

Related Questions

I am importing data into a sql table from a csv using an xml
I have some questions about importing data from Excel/CSV File into SQL Server. Let
I am using openrowset to import a csv file into SQL Server. One of
I am importing csv to db using bulk insert. It is the comma delimited
I'm importing a .CSV into an application with the following: if (($handle = fopen($file,
I am importing data from a CSV file into a postgreSQL table. The table
I am importing approx 350,000 lines from a CSV file into MySQL using PHP
In my iPhone app, I am importing CSV file into SQlite database using CHCSV
I'm importing a CSV into a MySQL table with LOAD DATA INFILE . One
I'm trying to insert some data into a table from a csv document which

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.