By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,454 Members | 3,191 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,454 IT Pros & Developers. It's quick & easy.

Problem with casting integer values to enum

P: n/a
Hi there,
I have an several enum types that starts from a nunmber other than 0.
For example:
public enum InternalStatus
{
Pending = 1,
Ported = 2,
Suspended = 3
}
I put this values in a int column of a MSSQL table.

When I try to read tha values back from the database and cast it to
the enuum type, the casting acts as the enum type starts from 0.

I tried Enum.Parse, but it didn't help.

Any suggestion...?

Aug 17 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Aug 17, 9:35 am, mitdej <mit...@gmail.comwrote:
I have an several enum types that starts from a nunmber other than 0.
For example:
public enum InternalStatus
{
Pending = 1,
Ported = 2,
Suspended = 3
}
I put this values in a int column of a MSSQL table.

When I try to read tha values back from the database and cast it to
the enuum type, the casting acts as the enum type starts from 0.

I tried Enum.Parse, but it didn't help.

Any suggestion...?
That sounds very unlikely to me. Could you post a short but complete
example showing the problem? The database side should be irrelevant,
as by the time you're casting you should already have the value as an
integer.

Jon

Aug 17 '07 #2

P: n/a
This is the problem code. Now that I look closely to the code it is
the opposite situation. Converting the enumeration to int value.

psn.RemoveSent((int)PortingNotification_WS.CDBMess ageType.PortingFromDonor_Notification
+1, Convert.ToInt32(dr["OperatorID"]), fromDate, toDate))

This is called from a Client App which is calling a web service and
the enumeration is trransferred as part of the proxy class.

The enumeration is on the server side and is defined as:

public enum CDBMessageType
{
SuspensionOfService_Notification = 1,
TerminateSuspension_Notification = 2,
Disconnection_Notification = 3,
RoutingErrors_Notification = 4,
PortingFromDonor_Notification = 5,
PortAccross_Notification = 6,
PortingAcceptance_Notification = 7,
PortingRejection_Notification = 8,
CancelPorting_Notification = 9,
ChangeInAssignedSeriesOfSubscriberNumbers_Notifica tion = 10
}

As You can see I have to add 1 to the value of the enumeration so it
can be casted to the correct int.
I think that WSDL doesn't transfer the information of the values of
the enuumeration types.
Any smarter solution?

Aug 17 '07 #3

P: n/a
On Aug 17, 10:58 am, mitdej <mit...@gmail.comwrote:

<snip>
This is called from a Client App which is calling a web service and
the enumeration is trransferred as part of the proxy class.
That may well be the problem. Have you tried looking at the XML
responses with something like Fiddler?

Jon

Aug 17 '07 #4

P: n/a
I haven't heard about fiddler :)

this is the enumeration as is generated in the proxy class:

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("Sy stem.Xml",
"2.0.50727.832")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespac e="http://
tempuri.org/")]
public enum CDBMessageType {

/// <remarks/>
SuspensionOfService_Notification,

/// <remarks/>
TerminateSuspension_Notification,

/// <remarks/>
Disconnection_Notification,

/// <remarks/>
RoutingErrors_Notification,

/// <remarks/>
PortingFromDonor_Notification,

/// <remarks/>
PortAccross_Notification,

/// <remarks/>
PortingAcceptance_Notification,

/// <remarks/>
PortingRejection_Notification,

/// <remarks/>
CancelPorting_Notification,

/// <remarks/>
ChangeInAssignedSeriesOfSubscriberNumbers_Notifica tion,
}

there are no assigned int values to the enumeration values, so I Guess
this is the problem.
Maybe Microsoft team should be informed about this.

Anyway thank You for Your quick responses to my posts.

Aug 17 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.