复制代码 代码如下:
int number = 0;
string connstr = @"Data Source=./SQLEXPRESS;AttachDbFilename=C:/Users/lando/Desktop/UML Extension/MyPratices/WebServices/App_Data/Database1.mdf;Integrated Security=True;User Instance=True";
using (SqlConnection conn = new SqlConnection(connstr))
{
conn.Open();
string str = "select * from Test";
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = str;
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
string name = dr["Name"].ToString();
DateTime dt = dr.GetDateTime(dr.GetOrdinal("InputDate"));
<STRONG>if (dr["Name"] == null) { number += 1; } </STRONG> }
}
}
if (number == 0)
Label1.Text = "不存在Name为null的值";
else
Label1.Text = "Name为空值的个数为:" + number;
复制代码 代码如下:
if (dr["Name"] == DBNull.Value)
{
number += 1;
}
复制代码 代码如下:
if (Convert.IsDBNull(dr["Name"]))
{
number += 1;
}
新闻热点
疑难解答
图片精选