I\'m having a \"Specified cast is not valid\" error. Windows form application in C#. I\'m trying to retrieve a value from a table. The value is either a smallint, or a numer
Silly suggestion, maybe - but have you considered trying this - grab the result from your SqlDataReader
as an instance of object
and then checking what type it is? No one can tell you better what it really is than the CLR type system! :-)
using (SqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
object obj = rdr["quantity"];
if(obj != null)
{
string objType = obj.GetType().FullName;
}
}
}
If you do get a value back, you can check what type it is and hopefully convert it accordingly, depending on your results.