Getting a byte array stored in an INT field in a database

How do I get the byte array stored in an integer column in my database?

First I do it as int and then as byte []?

byte [] permissions = (byte) Convert.ToInt (dr ["myField"]);

?

0


source to share


1 answer


Well, the data is stored as an integer. How do you want to convert this to a byte array. Given the input, say 12345, what should the output be?

Why are you trying to store a byte array in an integer column?

EDIT: Now that we know that these are basically the flags you want, I would not convert it to a byte array, I would use an enum:



[Flags]
public enum Permissions
{
    Read = 1,
    Write = 2,
    Execute = 4,
    Guillotine = 8,
    Lynch = 16
    // etc
}

      

Then you can just throw:

Permissions permissions = (Permissions) (int) dr["Field"]

      

+1


source







All Articles