我從數據庫中獲取數據,並將其填充到域object.Lets說如何識別數據庫中的值是否爲null或不在.Net 2.0中?
public class A
{
int? ai;
public int? AI
{
get { value = ai;}
Set { ai = value; }
}
}
,所以我創造了主類域對象。
class TestClass
{
static void Main(string[] args)
{
class A objData = new A();
// here some logic for creating connection to the database and calling the datareader to fetch the //data.
int temp =(int) objDataReader["aiDAta"];
objData.ai = temp == null? 0: temp;
func(objData);
}
}
public void func(A objData)
{
// Here i want to display the value of objData.ai only if its database value is not null.since i was //already assigned 0,if the value from the database is null...how can i able to identify whether the value //from the database is null or not? also,In database "aiDAta" will have the value range from 0 - 99.
}
}
在這裏,我想顯示objData.ai的價值只有當它的數據庫值不null.since我已經分配0,如果從數據庫中值爲空...我如何能夠確定數據庫中的值是否爲空?在數據庫中,「aiDAta」的取值範圍是0 - 99.
我被分配 「0」,如果該值來自數據庫的是null in() –
如果您想保留「它在數據庫中爲空」信息,請允許可爲空的完成其工作,並簡單地存儲空引用。畢竟,你確實是這樣宣佈的。 –
asawyer