Re: Why "Specified cast is not valid" error?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jack MacRank (jack_at_macrank.com)
Date: 11/22/04


Date: Mon, 22 Nov 2004 17:21:01 GMT

Stefan,

I set a breakpoint and looked at the GetType() of "retval" after the query
executed. I was surprised to see it was of Int64 type. I didn't know
C#/.NET automatically converted an object variable to another type...I
thought it would just be a generic object type and then I could cast it to
whatever I wanted it to.

I'm still a little confused why I can't cast an Int64 to String but I will
take your advice and use .ToString() and Convert.ToInt32() when I want a
string or integer.

Thanks to everyone who responded to my question!



Relevant Pages

  • Re: Why "Specified cast is not valid" error?
    ... I was surprised to see it was of Int64 type. ... > thought it would just be a generic object type and then I could cast it to ... > string or integer. ... read a good book on the basics of .NET, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: invalid class typecast
    ... > Using TLargeIntField field type as follows, ... typecast exception. ... Why do you cast it as TLargeInt? ... This means the INT64 type while MS Access ...
    (borland.public.delphi.database.ado)
  • Re: int32 Vs Int
    ... FYI there is also an int64 type ... couldn't find a reference to this type. ... the same as string Vs String and that int is simply a shortened form of ... int32 - both of them representing 32 bit signed integers? ...
    (microsoft.public.dotnet.languages.csharp)