关于查询为空table.rows.count不等于0
stringsql_label="selectsum(Ptotal)asPtotal,sum(Pum)asPum,sum(Qty)asQtyfromTestRecord_...
string sql_label = "select sum(Ptotal) as Ptotal,sum(Pum) as Pum,sum(Qty) as Qty from TestRecord_Basic where Id in (select distinct(Id) from TestRecord where TestTime=@ddate) ";
SqlCommand com_label = new SqlCommand(sql_label, con);
com_label.CommandText = sql_label;
com_label.Parameters.Add("@ddate", SqlDbType.DateTime);//向sql指令中添加一个参数@ddate,类型是datetime
com_label.Parameters["@ddate"].Value = TextBox1.Text;
SqlDataAdapter sda_label = new SqlDataAdapter(com_label);
DataTable dt_label = new DataTable();
sda_label.Fill(dt_label);
if (dt_label.rows.count==0)
{
语句一
}
else
{
语句二
}
当查询为空时,dt_label.rows.count为什么不等于0而是等1.if语句也总是执行语句二。请问这是哪出了问题 展开
SqlCommand com_label = new SqlCommand(sql_label, con);
com_label.CommandText = sql_label;
com_label.Parameters.Add("@ddate", SqlDbType.DateTime);//向sql指令中添加一个参数@ddate,类型是datetime
com_label.Parameters["@ddate"].Value = TextBox1.Text;
SqlDataAdapter sda_label = new SqlDataAdapter(com_label);
DataTable dt_label = new DataTable();
sda_label.Fill(dt_label);
if (dt_label.rows.count==0)
{
语句一
}
else
{
语句二
}
当查询为空时,dt_label.rows.count为什么不等于0而是等1.if语句也总是执行语句二。请问这是哪出了问题 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询