单独执行SQL语句成功,用C#执行SQL语句提示DBNull,很无奈~~

y7j1m51494 2016-04-18 08:43:15
SQL = String.Format("select a.snum1 + b.snum2 + c.snum3 + d.snum4 + e.snum5 from (select sum(cast(首次收款金额 as decimal(18,2))) snum1 from salescontentservice where 首次收款日期 >= '{0}' and 首次收款日期 <= '{1}')a , (select sum(cast(二次收款金额 as decimal(18,2))) snum2 from salescontentservice where 二次收款日期 >= '{2}' and 二次收款日期 <= '{3}')b , (select sum(cast(三次收款金额 as decimal(18,2))) snum3 from salescontentservice where 三次收款日期 >= '{4}' and 三次收款日期 <= '{5}')c ,(select sum(cast(四次收款金额 as decimal(18,2))) snum4 from salescontentservice where 四次收款日期 >= '{6}' and 四次收款日期 <= '{7}')d ,(select sum(cast(五次收款金额 as decimal(18,2))) snum5 from salescontentservice where 五次收款日期 >= '{8}' and 五次收款日期 <= '{9}')e", startdate, enddate, startdate, enddate, startdate, enddate, startdate, enddate, startdate, enddate);
object theit = dbt.ExecuteObject(SQL);
if (theit != System.DBNull.Value)
{
this.label1.Text = theit.ToString();
}
else

this.label1.Text = "";
...全文
188 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoxiangqing 2016-04-18
  • 打赏
  • 举报
回复
看返回的数据是什么,监控一下
y7j1m51494 2016-04-18
  • 打赏
  • 举报
回复
dbt.ExecuteObject(SQL);为执行此SQL并返回object值
y7j1m51494 2016-04-18
  • 打赏
  • 举报
回复
SqlDateTime startdate = new SqlDateTime(dateTimePicker1.Value); SqlDateTime enddate = new SqlDateTime(dateTimePicker2.Value);

22,302

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧