一:SQL Server中的NULL和.NET中的DBNULL以及面向编程语言中的NULL的区别
二:实例
SqlConnection conn = SqlHelper.GetConnection(Convert.ToInt16(CustomEnum.DBCallType.其他库));
string sqlText = "SELECT * FROM NameAndSubjectAndGrade WHERE ID = 15";
SqlDataReader dr = SqlHelper.ExecuteReader(conn, CommandType.Text, sqlText);
if (dr.Read())
{
if (dr["Name"] is DBNull)
{
this.txtName.Text = "";
}
else
{
this.txtName.Text = dr["Name"].ToString();
}
if (dr["Subject"] is DBNull)
{
this.txtSubject.Text = "";
}
else
{
this.txtSubject.Text = dr["Subject"].ToString();
}
if (dr["Grade"] is DBNull)
{
this.txtSubject.Text = "";
//也可以写成如下方式,DBNULL是可以转化为String类型的,转化后的值为""
this.txtSubject.Text = dr["Grade"].ToString();
}
else
{
this.txtGrade.Text = dr["Grade"].ToString();
}
}