The value of the variable I’m trying to write to fTotal comes from a SQL query on a column with a type of float. I think my problem may have something to do with boxing and unboxing variables. I plan to research this to understand it better. Any input on what causes the errors in the two code examples below will be invaluable to my understanding of this. In each example the error rendered follows the // on the line generating the error.
Example 1:
float fTotal = 0.00F;
fTotal = (r.GetFloat(0)); //Exception Details: System.InvalidCastException: Specified cast is not valid
LTotal.Text = (fTotal.ToString());
Example 2:
float fTotal = 0.00F;
fTotal = (r.GetString(0)); //Compiler Error Message: CS0029: Cannot implicitly convert type 'string' to 'float'
LTotal.Text = (fTotal.ToString());
Thank you all for your patience and help!
iRead
Example 1:
float fTotal = 0.00F;
fTotal = (r.GetFloat(0)); //Exception Details: System.InvalidCastException: Specified cast is not valid
LTotal.Text = (fTotal.ToString());
Example 2:
float fTotal = 0.00F;
fTotal = (r.GetString(0)); //Compiler Error Message: CS0029: Cannot implicitly convert type 'string' to 'float'
LTotal.Text = (fTotal.ToString());
Thank you all for your patience and help!
iRead