老公小儿麻痹腿没力:C#中数据库问题?

来源:百度文库 编辑:高考问答 时间:2024/03/29 05:30:13
C#中在使用SqlDataReader dt时,如果数据库中有字段为NULL时,不能使用dt.GetString(i),该怎么办,如何判断?

假设sql 为:SqlCommand cmd=new SqlCommand("select id,name from test where id=1");其中id=1 name 为NULL
下面的方法你试一试,我试过是可以
SqlDataReader sdr=cmd.ExecuteReader();
sdr.Read();
if(sdr[1].ToString()=="")
{
this.Label1.Text="null";
}
else
{
this.Label1.Text="not null";;
}