Reputation: 253
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);
Upvotes: 0
Views: 184
Reputation: 91545
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.
Upvotes: 6
Reputation: 417
Range of UInt16
is 0 to 65,535. It doesn't cover negative values. You should try the regular Int16
.
Upvotes: 5