2014-01-21 66 views
0

我有这个SQL查询应该返回一个0的计数,但我想这是很糟糕的构建。SQL计数没有返回正确的计数

这里是SQL代码,我执行

string cmdText = @"SELECT count(*) 
        From Apointement 
        WHERE [email protected] AND 
         [email protected] AND 
         TrailHour=trialhour"; 

SqlCommand cmd = new SqlCommand(cmdText, con); 

cmd.Parameters.AddWithValue("@emailClient", Convert.ToString(Session["email"])); 
cmd.Parameters.AddWithValue("@trialdate",dDateApt); 
cmd.Parameters.AddWithValue("@trialhour", sHourApt); 

if (con.State == ConnectionState.Closed) 
{ 
    con.Open(); 
} 

int nbrofRec = (int) cmd.ExecuteScalar(); 
if (nbrofRec >= 1) 

这对于数查询返回1。

查询中的数据如下:

email  = [email protected] 
trialdate = 1/27/2014 12:00:00AM 
trialhour = 10:00 

数据库

email  = [email protected] 
trialdate = 1/27/2014 
trialhour = 12:00  <=== notice the only appointment is at 12:00 not at 10:00 

日期我无法找出哪些元素是错误的。

+1

简单的错字,但它很好奇没有错误信息的原因。 'TrialHour = trialhour'它总是对的 – Steve

+0

@Steve是啊,我也在想这个:) – Shiva

回答