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

  • Home
  • SEARCH
  • 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 8318123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:51:04+00:00 2026-06-08T21:51:04+00:00

In my c# code, I have a double that I am trying to set

  • 0

In my c# code, I have a double that I am trying to set to the value that is in my SQL Management 2008 R2 database that is of type float (which corresponds to a double in c#, right?). When I use this syntax

double x = (double)reader["column1"]; //reader is SqlDataReader object

I get the error “specified cast is not valid.”

What gives?

  • 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-08T21:51:06+00:00Added an answer on June 8, 2026 at 9:51 pm

    I would suggest using the helper classes available through the SqlDataReader object…

    double dbl = reader.GetDouble(reader.GetOrdinal("DoubleColumn"));
    

    If there is a chance the column could be null, you should account for that…

    double dbl = (reader["DoubleColumn"] != DBNull.Value ? dr.GetDouble(dr.GetOrdinal("DoubleColumn")) : 0.0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code that takes a double value and converts it to
Here's the c# code that I have: private double get806Fees (Loan loan) { Loan.Fee.Items
In a C++ code I have a matrix of double variables which I print
I'm trying to set up Excel so that the cell's value that is selected
Following is the code that I have been trying to deploy. As you can
Here is the code I have written for Rectangle class. class Rectangle (l: Double,
I have the following code.... double num1 = Double.parseDouble(textArea_price.getText()); double num2 = Double.parseDouble(textArea_quantity.getText()); double
I have the following code: void foo() { vector<double> v(100,1); // line 1 //
I have this (working) CPU code: #define NF 3 int ND; typedef double (*POT)(double
I'm writing code in C++ and have defined PI as: const double MathConstants::PI =

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.