RE: InvalidCastException
From: Ilya Tumanov [MS] (ilyatum_at_online.microsoft.com)
Date: 04/22/04
- Next message: William Ryan eMVP: "Re: adding event handlers for windows controls"
- Previous message: Flying Whiz: "Adding files when creating CAB file in .NETCF"
- In reply to: Aris: "RE: InvalidCastException"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 22 Apr 2004 18:07:38 GMT
I see... Well, as I've explained in my previous post, you can not just cast
one enum to another.
You will get an enum with the same underlying numeric value, but the
meaning might be totally different.
In many cases there's no meaning at all.
For example, you can go ahead and cast System.Data.AcceptRejectRule to
System.IO.FileAccess, but it will accomplish nothing.
In this case there's a logical link between DbType and SqlDbType.
However, casting one to another won't work because underlying numeric
values are different for the same logical values.
It's up to you to connect them on a logical level. You have to look up
matching values using table or switch statement. Good luck.
Best regards,
Ilya
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
> Thread-Topic: InvalidCastException
> thread-index: AcQoWRymUuqIP2aRQe2iG3XKXcwM3g==
> X-WN-Post: microsoft.public.dotnet.framework.compactframework
> From: "=?Utf-8?B?QXJpcw==?=" <anonymous@discussions.microsoft.com>
> References: <66A62F8B-6B6F-4D0D-B68D-10D307E5A657@microsoft.com>
<uzLhbB9JEHA.3088@cpmsftngxa10.phx.gbl>
> Subject: RE: InvalidCastException
> Date: Thu, 22 Apr 2004 04:01:07 -0700
> Lines: 1
> Message-ID: <8E1A3865-5E89-42E2-83C1-4BAD4128AFF5@microsoft.com>
> MIME-Version: 1.0
> Content-Type: text/plain;
> charset="Utf-8"
> Content-Transfer-Encoding: 7bit
> X-Newsreader: Microsoft CDO for Windows 2000
> Content-Class: urn:content-classes:message
> Importance: normal
> Priority: normal
> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
> Newsgroups: microsoft.public.dotnet.framework.compactframework
> Path: cpmsftngxa10.phx.gbl
> Xref: cpmsftngxa10.phx.gbl
microsoft.public.dotnet.framework.compactframework:51509
> NNTP-Posting-Host: tk2msftcmty1.phx.gbl 10.40.1.180
> X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
>
> What am I trying to do is to build an application that is database
independent. That is my application uses IdbCommand, IdbDataReader etc...
and in a switch statement I retrieve the name of the database from a
configuration file.So when I pass a DbType in a IdbParameter, I cast it as
an SqlDbType in a SqlParameter.
>
- Next message: William Ryan eMVP: "Re: adding event handlers for windows controls"
- Previous message: Flying Whiz: "Adding files when creating CAB file in .NETCF"
- In reply to: Aris: "RE: InvalidCastException"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|