sql语句在数据库执行的结果对,为什么在C#里读的结果不对》
selectInquiryDateasstrInquiryDate,HourSegmentasstrHourSegment,sum(MinTruck_Number)+su...
select InquiryDate as strInquiryDate,HourSegment as strHourSegment,sum(MinTruck_Number)+sum(MidTruck_Number)+sum(LargeTruck_Number)+sum(MinCar_Number)+sum(LargeCar_Number)+sum(Trailer_Number)+sum(OutsizeTruck_Number) as SumProduct from HourNumberTable group by HourSegment,InquiryDate order by HourSegment desc
这是SQL语句,数据库显示结果对
string strsql = "select InquiryDate as strInquiryDate,HourSegment as strHourSegment,sum(MinTruck_Number)+sum(MidTruck_Number)+sum(LargeTruck_Number)+sum(MinCar_Number)+sum(LargeCar_Number)+sum(Trailer_Number)+sum(OutsizeTruck_Number) as SumProduct from HourNumberTable group by HourSegment,InquiryDate order by HourSegment";
SqlCommand cmd = new SqlCommand(strsql, conn);
string SumProduct = cmd.ExecuteScalar().ToString().Trim();
Response.Write(SumProduct);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
string strHoursegment = dr["strHourSegment"].ToString();
string strInquiryDate = dr["strInquiryDate"].ToString();
}
else
{
Response.Write("1111");
}
dr.Close();
conn.Close();
这是C#中的,SumProduct返回值不对,strHoursegment,strInquiryDate是空值???
string strsql = "select InquiryDate as strInquiryDate,HourSegment as strHourSegment,sum(MinTruck_Number)+sum(MidTruck_Number)+sum(LargeTruck_Number)+sum(MinCar_Number)+sum(LargeCar_Number)+sum(Trailer_Number)+sum(OutsizeTruck_Number) as SumProduct from HourNumberTable group by HourSegment,InquiryDate order by HourSegment";
在C#中,把 InquiryDate as strInquiryDate,HourSegment as strHourSegment去掉,SumProduct值正确,这是什么原因呢? 展开
这是SQL语句,数据库显示结果对
string strsql = "select InquiryDate as strInquiryDate,HourSegment as strHourSegment,sum(MinTruck_Number)+sum(MidTruck_Number)+sum(LargeTruck_Number)+sum(MinCar_Number)+sum(LargeCar_Number)+sum(Trailer_Number)+sum(OutsizeTruck_Number) as SumProduct from HourNumberTable group by HourSegment,InquiryDate order by HourSegment";
SqlCommand cmd = new SqlCommand(strsql, conn);
string SumProduct = cmd.ExecuteScalar().ToString().Trim();
Response.Write(SumProduct);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
string strHoursegment = dr["strHourSegment"].ToString();
string strInquiryDate = dr["strInquiryDate"].ToString();
}
else
{
Response.Write("1111");
}
dr.Close();
conn.Close();
这是C#中的,SumProduct返回值不对,strHoursegment,strInquiryDate是空值???
string strsql = "select InquiryDate as strInquiryDate,HourSegment as strHourSegment,sum(MinTruck_Number)+sum(MidTruck_Number)+sum(LargeTruck_Number)+sum(MinCar_Number)+sum(LargeCar_Number)+sum(Trailer_Number)+sum(OutsizeTruck_Number) as SumProduct from HourNumberTable group by HourSegment,InquiryDate order by HourSegment";
在C#中,把 InquiryDate as strInquiryDate,HourSegment as strHourSegment去掉,SumProduct值正确,这是什么原因呢? 展开
3个回答
展开全部
是不是跟
if (dr.Read())
{
string strHoursegment = dr["strHourSegment"].ToString();
string strInquiryDate = dr["strInquiryDate"].ToString();
}
else
{
Response.Write("1111");
}
这段有关?
if (dr.Read())
{
string strHoursegment = dr["strHourSegment"].ToString();
string strInquiryDate = dr["strInquiryDate"].ToString();
}
else
{
Response.Write("1111");
}
这段有关?
追问
那我错在哪了呢?
追答
这不是比数据库里查询多了个条件么,如果查询代码一样,那就是这个条件的问题了
展开全部
再仔细调试一下,吧sql语句复制一下到数据库中运行看好不好用!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你最好仔仔细细检查一下的你sql语句 我看了一下你的代码 没问题 要有问题也是sql语句不对,你确定你在C#里的sql语句和你在数据库中一样吗??
追问
确定是一样的,我粘贴过来了,应该能看到吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询