SqlDataReader.GetFloat

J

John Straumann

Hi all:

I have a SQL Data Table with some values of type "float" (set in SQL table
design). I am trying to read the values via a SqlDataReader (this app does
not use DataGrids) and for some reason I am getting a
"Specified cast is not valid" message.

Anyone out there know wassup with that?

Thanks.

John.
 
N

Nicholas Paldino [.NET/C# MVP]

John,

What are you trying to cast to? Are you trying to cast to double, or to
decimal? The type that is returned should be SqlFloat. If you use the
debugger, you can assign the value to an object variable, and see the type
of the object returned in the debugger.

Hope this helps.
 
J

Jon Skeet [C# MVP]

John Straumann said:
I have a SQL Data Table with some values of type "float" (set in SQL table
design). I am trying to read the values via a SqlDataReader (this app does
not use DataGrids) and for some reason I am getting a
"Specified cast is not valid" message.

Anyone out there know wassup with that?

Are you trying to cast it to a float? If so, that's probably what's
wrong. Somewhat confusingly, a SQL Float corresponds to a C# double.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top