简体   繁体   中英

Negative values not reflecting in the output

I have a database column which takes values 1 , 0 , -1 . I am using uint and GetUInt16 as seen below in my class and code snippet. Somehow the negative value isn't reflected. What datatype I should use to see the negative values in the class and in rdr ?

public class Postcommit
{
    public string software_image_build { get; set; }
    public uint TestStatus { get; set; }
}

Code snippet:

  PCS[i++].TestStatus = rdr.GetUInt16(1);

You're using a uint . the u stands for unsigned meaning it can't be negative (the "sign" refers to the "negative sign"). You should use a normal int . Similarly, you should use rdr.GetInt16(1) to get the value.

public class Postcommit
{
    public string software_image_build { get; set; }
    public int TestStatus { get; set; }
}

...

PCS[i++].TestStatus = rdr.GetInt16(1);

So at every step along the way, from your database to your code, every single type must be set to an integer, not an unsigned integer.

Range of UInt16 is 0 to 65,535. It doesn't cover negative values. You should try the regular Int16 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM