Hier eine kleine Funktion um ein beliebiges Objekt in einen gültigen Byte-Wert umzuwandeln:
static public byte ToValidByte(object n) {
if(n==null) return 0;
if(n.GetType() == typeof(string)) {
try {
return byte.Parse((string)n);
}
catch( Exception ) {
return 0;
}
}
if(n.GetType() == typeof(byte)) {
return (byte)n;
}
if(n.GetType() == typeof(decimal)) {
return decimal.ToByte((decimal)n);
}
return 0;
}