samedi 21 novembre 2015

C# Cast a enum InvalidCastException error

So i have this old code that uses Firebird, i took the code from there since it worked perfectly, but here it doesnt. and throws me a InvalidCastException.

So wat am i trying

animal.FeedScheduleType = (BcFeedScheduleType)drAnimal["feedschedule_type"];

So i try to pull something out my datatable and place it in animal.FeedScheduleType. Now my cast points a a public enum

    public enum BcFeedScheduleType
{
    Default = 0,
    FromList = 1,
    Group = 2
}

and animal.FeedScheduleType is

private BcFeedScheduleType _feedScheduleType;

public BcFeedScheduleType FeedScheduleType
    {
        get { return _feedScheduleType; }
        set { _feedScheduleType = value; }
    }

But whenever it hits this it throws me the InvalidCastException error and i dont know why, i searched here and google but was unable to find anything about casts like this.

Aucun commentaire:

Enregistrer un commentaire