Retrieving a byte array stored in a INT field in the database

how do I retrieve the byte array stored in an integer column in my database?

Do I first case it as int, then as byte[] ?

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



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

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

EDIT: Now that we know that it's basically flags you're after, I wouldn't convert it to a byte array, I'd use an enum:

public enum Permissions
    Read = 1,
    Write = 2,
    Execute = 4,
    Guillotine = 8,
    Lynch = 16
    // etc

Then you can just cast:

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

Need Your Help

SQL select distinct with unique ids

sql sqlite

I'm sorry, my SQL is a bit rusty so this might be trivial, but I can't figure it out.