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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:16:01+00:00 2026-05-23T06:16:01+00:00

My SQL data of column Price is of type float. When I use DataReader

  • 0

My SQL data of column Price is of type float.
When I use DataReader to read in a row and try to access the column value as

reader["Price"]

I got a compiler error: “The best overloaded method match for decimal.Parse(string) has some invalid arguments.”

I want assign this value to a decimal variable, how do I do so?
I got the compiler error above when I tried:

decimal price;
price = decimal.Parse(reader["Price"]);
  • 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-23T06:16:02+00:00Added an answer on May 23, 2026 at 6:16 am

    The return type for reader["Price"] is object. To do what you’re trying to do use this:

    price = decimal.Parse(reader["Price"].ToString()); 
    

    However, if there’s the slightest change you can end up with a string that cannot be converted to a Decimal consider using the Decimal.TryParse Method which will allow you to determine if the conversion was successful.

    EDIT
    The SqlDataReader has a number of different GetXXX methods that allow you to retrieve typed data from a column in a DataReader without first having to cast to/from an intermediate type. I originally advised you to use SqlDataReader.GetDecimal because I saw the type you wanted to retrieve is a decimal. I see now that the SQL data type of the this data is actually float so I was going to advise that you use SqlDataReader.GetFloat. I tested this though and got an invalid cast exception. The reason for this is that the SQL float is not compatible with the .NET float data type.

    So I checked table in SQL Server Data Types and Their .NET Framework Equivalents on MSDN and found that the SQL float is the equivalent to the .NET double. I tried SqlDataReader.GetDouble and was able to retrieve data without error. Since you want a decimal though, you’ll need to cast:

    price = (decimal)reader.GetDouble(reader.GetOrdinal("Price"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Which sql data type should we use for number bases primary key: int bigint
I have two column in Sql server Amount as real type Price as bigint
I use Entity Framework to access my SQL data. I have some constraints in
How can i export table data with column name in text file in sql
I need a SQL query to make all data in a column UPPER CASE?
I understand that when adding a column to a table containing data in SQL
I've got a sql query (using MS-SQL 2005) that generates data with these columns:
I use RedGate SQL data compare and generated a .sql file, so I could
We've purchased a tool from Redgate called SQL Data Compare. I use it mainly
I'm getting an exception from SQL Data Reader (MS SQL as datastore) and I'd

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.