I'm retrieving some data with a SqlDataReader and trying to convert one of these objects to a float (the same as its data type in the database).
What I have:
u.unitid = (float)Convert.ToSingle((reader["UNITID"]));
This returns a "0" for every unitid.
ToSingletofloatsince it is already afloat. Have you tried thereader.GetFloat()method? What is the column type ofUNITEDin the database?Getxxxxmethods such asGetSingle()? If it always returns 0 for any row consider that the query may be wrong etcSingleis the CLR name that C# aliases asfloat. They are the same, the cast is not necessary.