c# - How to handle a NULL value in reader.GetByte(x)? -


i've got following block of code:

//check see if unique_id 10 or 11 , process accordingly //10 = both boxes, 11 = rework if (reader.getbyte(16) == 10) {    int es = convert.toint32(reader["escalated"]);    if (es == 0)    {       chkescalated.checked = false;    }    else    {       chkescalated.checked = true;       chkescalated.visible = true;       lblescalated.visible = true;       chkrework.visible = true;       lblrework.visible = true;     } } else if (reader.getbyte(16) == 11) { } else { } 

the problem have is, sometimes, reader.getbyte(16) null. , when happens, error:

data null. method or property cannot called on null values.

i'm still of novice, i'm sure there's obvious i'm missing, can't find it.

use isdbnull method :

//check see if unique_id 10 or 11 , process accordingly //10 = both boxes, 11 = rework if (reader.isdbnull(16)) {    //add here code handle null value } else {    //use switch read value 1 time    switch (reader.getbyte(16))    {      case 10:        int es = convert.toint32(reader["escalated"]);        if (es == 0)        {           chkescalated.checked = false;        }        else        {           chkescalated.checked = true;           chkescalated.visible = true;           lblescalated.visible = true;           chkrework.visible = true;           lblrework.visible = true;         }         break;        case 11:         break;        default:         break;    } } 

Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -