Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 559301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:13:26+00:00 2026-05-13T12:13:26+00:00

Okay, for whatever reason I can’t seem to figure this little problem out. I

  • 0

Okay, for whatever reason I can’t seem to figure this little problem out.

I have the following enum:

public enum EFeedType
{
    TypeOne = 1,
    TypeTwo = 2
}

Now, I am going to be getting the numeric value from a database. Well, I need to cast the int value from the DB to the enum type:

EDIT:
The database type is integer, so I do not need to cast from string.
END EDIT

EFeedType feedType = (EFeedType) feedId;

However, when I do this, and pass in value of 2 I get the following error:

Instance validation error: ‘2’ is not a valid value for [Namespace Goes Here].EFeedType.

Any thoughts on what I might be doing wrong or missing?

EDIT
Here is the code I am using:

        //GetFeed will return an int value which is pulled from the database
        int feedId = new FeedEngine().GetFeed("FeedName");
        //Convert the ID to the Enum
        EFeedType feedType = (EFeedType) feedId;
        //Set the User Control FeedType Enum to the enum
        FeedControl.FeedType = feedType;
        //Show the user control
        FeedControl.Visible = true;

EDIT – More Info

Okay, after seeing JSkeet’s response, I see that If my feedId = 1 then it will set the enum value to TypeTwo instead of TypeOne like it should. Maybe I need a Default = 0 value in my enum for this to work? But there has to be a better way, because what if my values are not in sequence.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:13:27+00:00Added an answer on May 13, 2026 at 12:13 pm

    Your error won’t be coming from the line you showed it on. I strongly suspect it’s coming from this line:

    FeedControl.FeedType = feedType;
    

    My guess is that that property is doing some validation – and that it doesn’t know about the relevant value.

    EDIT: Note that if you do want to find out if a value is valid, use Enum.IsDefined. Enum.Parse will not throw an exception for an incorrect numeric value, so long as it’s in the right range.

    Have you really posted the exact code of the enum? Because if it doesn’t explicitly specify the “= 1” and “= 2” it will autoincrement from 0, and that will be your problem.

    If you could demonstrate all of this with a short but complete program it would really help. There’s no need to go to the database, and no need to do anything with a user control.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay let me see if I can explain this right. In wordpress we have
Okay, this has been absolutely infuriating to debug, I have finally figured out what
Okay, so for whatever reason I have ended up with a situation where the
Okay, so this will probably be closed or whatever, I don't care. I have
How can I re-use a function? Okay lets say I have this main function
This might be a n00bish question, but whatever. Is okay to use exceptions for
Okay, next PHPExcel question. I have an HTML form that users fill out and
Okay this question is very simple: I have a facebook page, and a website.
Okay, I have the following create action #posts_controller, nested resource under discussions def create
Okay, I am stumped on this one and need some quick help. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.