473,657 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with casting integer values to enum

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
4 1980
On Aug 17, 9:35 am, mitdej <mit...@gmail.c omwrote:
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
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)PortingNot ification_WS.CD BMessageType.Po rtingFromDonor_ 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
{
SuspensionOfSer vice_Notificati on = 1,
TerminateSuspen sion_Notificati on = 2,
Disconnection_N otification = 3,
RoutingErrors_N otification = 4,
PortingFromDono r_Notification = 5,
PortAccross_Not ification = 6,
PortingAcceptan ce_Notification = 7,
PortingRejectio n_Notification = 8,
CancelPorting_N otification = 9,
ChangeInAssigne dSeriesOfSubscr iberNumbers_Not ification = 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
On Aug 17, 10:58 am, mitdej <mit...@gmail.c omwrote:

<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
I haven't heard about fiddler :)

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

/// <remarks/>
[System.CodeDom. Compiler.Genera tedCodeAttribut e("System.Xml ",
"2.0.50727.832" )]
[System.Serializ ableAttribute()]
[System.Xml.Seri alization.XmlTy peAttribute(Nam espace="http://
tempuri.org/")]
public enum CDBMessageType {

/// <remarks/>
SuspensionOfSer vice_Notificati on,

/// <remarks/>
TerminateSuspen sion_Notificati on,

/// <remarks/>
Disconnection_N otification,

/// <remarks/>
RoutingErrors_N otification,

/// <remarks/>
PortingFromDono r_Notification,

/// <remarks/>
PortAccross_Not ification,

/// <remarks/>
PortingAcceptan ce_Notification ,

/// <remarks/>
PortingRejectio n_Notification,

/// <remarks/>
CancelPorting_N otification,

/// <remarks/>
ChangeInAssigne dSeriesOfSubscr iberNumbers_Not ification,
}

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3100
by: martinacevedo | last post by:
I made a library in c++ gcc(3.4) with some classes. Within a classes, I have an enumerator type, the problem is when I use the library from another c++ project( the library is dynamic linked) I can't use a fully qualified name for accessing the enum values. The compiler says that the name is not a class or namespace ex: in the library I have a class like this .. ... Test.h
2
5384
by: babylon | last post by:
I have an enum public enum MyEnum : int { X, Y } I have to do int a = (int) MyEnum.X; can i overload the operator or other means to do something like
1
2605
by: Fei Li | last post by:
Hi, Whi can help to expain what logic is when I cast enum a to b? Thanks
18
11340
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! I have created an enum list like this: enum myEnum : int { This = 2, That, NewVal = 10, LastItm
0
1712
by: Greg | last post by:
Not sure if this is best place for this problem, but here it is. I have a project that is simply a C# class that interfaces with an IFilter. This is so I can retreive the text from Word docs. I'm able to use this DLL without any problems within my test windows app, but not within my windows service (that's when I receive the casting exception). Here's the code (sorry it's long): VB Function within windows app and windows service:
6
4614
by: Jason Larion | last post by:
When working with enums, I've noticed some behaviour that seems completely counter-intuitive to me. I was wondering if someone here could help restore my sanity, or at least help me to understand the "why" of the behaviour. After dimensioning an enum of type integer, any attribute referenced seems to, by default, return the name of that attribute as a string, instead of the integer value assigned to it. The code snippet that follows...
7
2619
by: John Goche | last post by:
Hello, The following program compiler and runs fine under gcc and produces the output 3. However, I am not sure whether such behavior is legal. In particular, as a related question, how would I go about checking that a supplied integer is contained within the set of values of an enumeration? Is there a way to do this? Thanks,
4
1287
by: PokerMan | last post by:
Hi guys, Maybe someone can explain thisi have this enum: public enum LimitType : int { BottomLimit, TopLimit, Limit }
11
6943
by: MSNEWS | last post by:
HI Public Enum WindowStyles As UInteger WS_OVERLAPPED = 0x00000000 WS_POPUP = 0x80000000 WS_CHILD = 0x40000000 end enum In the above i get an error at
0
8310
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8827
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7333
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2731
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1620
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.