报错信息:

1. 

2. 

3. 

4. 

5. 

6. 

解决方法:

1. Data Layer SQL 语句取数据时,把其列值有为null的字段用0.00替换,(ISNULL的用法);

2.

        #region 查询工资信息
/// <summary>
/// 查询工资信息
/// </summary>
/// <param name="model"></param>
/// <param name="pageIndex"></param>
/// <param name="pageCount"></param>
/// <param name="ord"></param>
/// <param name="TotalCount"></param>
/// <returns></returns>
public static DataTable GetSalaryInfoByEmployee(SalaryInfoModel model, string ReportType, string DeptID, int pageIndex, int pageCount, string ord, string endmonth, ref int TotalCount)
{
#region 查询语句
StringBuilder searchSql = new StringBuilder();
searchSql.AppendLine(" SELECT ");
searchSql.AppendLine(" A.ID,A.ReprotNo,A.CompanyCD,A.DeptName,A.EmployeeID,A.EmployeeName,A.Remarks,");
searchSql.AppendLine("isnull(A.BFGJJ,0.00) BFGJJ,");
searchSql.AppendLine("isnull(A.BFGZ,0.00) BFGZ, ");
searchSql.AppendLine("isnull(A.BLGZ,0.00) BLGZ,");
searchSql.AppendLine("isnull(A.CTF,0.00) CTF, ");
searchSql.AppendLine("isnull(A.DTF,0.00) DTF,");
searchSql.AppendLine("isnull(A.FTF,0.00) FTF, ");
searchSql.AppendLine("isnull(A.GHF,0.00) GHF,");
searchSql.AppendLine("isnull(A.GJJ,0.00) GJJ,");
searchSql.AppendLine("isnull(A.GTS,0.00) GTS,");
searchSql.AppendLine("isnull(A.GWF,0.00) GWF,");
searchSql.AppendLine("isnull(A.JBGZ,0.00) JBGZ,");
searchSql.AppendLine("isnull(A.JiangJ,0.00) JiangJ,");
searchSql.AppendLine("isnull(A.JZZYBF,0.00) JZZYBF,");
searchSql.AppendLine("isnull(A.KCBJ,0.00) KCBJ, ");
searchSql.AppendLine("isnull(A.MTF,0.00) MTF, ");
searchSql.AppendLine("isnull(A.QT,0.00) QT, ");
searchSql.AppendLine("isnull(A.QTE,0.00) QTE, ");
searchSql.AppendLine("isnull(A.QTY,0.00) QTY, ");
searchSql.AppendLine("isnull(A.SBJ,0.00) SBJ, ");
searchSql.AppendLine("isnull(A.Total,0.00) Total, ");
searchSql.AppendLine("isnull(A.TotalOne,0.00) TotalOne, ");
searchSql.AppendLine("isnull(A.TotalTwo,0.00) TotalTwo, ");
searchSql.AppendLine("isnull(A.YBJ,0.00) YBJ, ");
searchSql.AppendLine("isnull(A.YLJ,0.00) YLJ ");
searchSql.AppendLine(" ,c.DeptName as DeptWprkName ");
searchSql.AppendLine(" ,Substring(b.ReportMonth, 1, 4) + '年' ");
searchSql.AppendLine(" + Substring(b.ReportMonth, 5, 2) + '月' ");
searchSql.AppendLine(" AS ReportMonth ");
searchSql.AppendLine(" FROM officedba.SalaryInfo a ");
searchSql.AppendLine(" left join officedba.SalaryReport b on a.ReprotNo=b.ReprotNo ");
searchSql.AppendLine(" left join officedba.DeptInfo c on b.DeptID=c.ID ");
searchSql.AppendLine(" left join officedba.EmployeeInfo d on a.employeeID=d.ID ");
searchSql.AppendLine(" WHERE ");
searchSql.AppendLine(" a.CompanyCD = @CompanyCD ");
searchSql.AppendLine(" AND b.ReportType = @ReportType "); #endregion //定义查询的命令
SqlCommand comm = new SqlCommand();
//公司代码
comm.Parameters.Add(SqlHelper.GetParameterFromString("@CompanyCD", model.CompanyCD));
comm.Parameters.Add(SqlHelper.GetParameterFromString("@ReportType", ReportType));
UserInfoUtil userInfo = (UserInfoUtil)SessionUtil.Session["UserInfo"];
if (userInfo.EmployeeID != && userInfo.EmployeeID != && userInfo.EmployeeID != && userInfo.EmployeeID != )
{
searchSql.AppendLine(" AND b.DeptId in (select emp.DepID from officedba.EmpAndDep emp where emp.EmpID=@EmployeeID) ");
comm.Parameters.Add(SqlHelper.GetParameterFromString("@EmployeeID", userInfo.EmployeeID.ToString()));
} #region 页面输入条件
//员工姓名
if (!string.IsNullOrEmpty(model.EmployeeName))
{
searchSql.AppendLine(" AND A.EmployeeName LIKE '%' + @EmployeeName + '%' ");
comm.Parameters.Add(SqlHelper.GetParameterFromString("@EmployeeName", model.EmployeeName));
} if (!string.IsNullOrEmpty(model.DeptName))
{
searchSql.AppendLine(" AND B.DeptID in (" + model.DeptName + ") ");
//comm.Parameters.Add(SqlHelper.GetParameterFromString("@DeptName", model.DeptName));
}
//所属月份
if (!string.IsNullOrEmpty(model.Month))
{
if (endmonth != "")
{
searchSql.AppendLine(" AND convert(int,b.ReportMonth) between @ReportMonth and @endReportMonth ");
comm.Parameters.Add(SqlHelper.GetParameterFromString("@endReportMonth", endmonth));
}
else
{
searchSql.AppendLine(" AND convert(int,b.ReportMonth) > @ReportMonth ");
}
comm.Parameters.Add(SqlHelper.GetParameterFromString("@ReportMonth", model.Month)); } if (!string.IsNullOrEmpty(DeptID))
{
searchSql.AppendLine(" AND (CHARINDEX(',' +LTRIM(d.DeptID),(@DeptID))>0 or CHARINDEX(RTRIM(d.DeptID)+',',(@DeptID))>0 or CHARINDEX(LTRIM(d.DeptID),(@DeptID))>0) ");
comm.Parameters.Add(SqlHelper.GetParameterFromString("@DeptID", DeptID));
}
#endregion

3. SQL  Statements

 SELECT
A.ID,A.ReprotNo,A.CompanyCD,A.DeptName,A.EmployeeID,A.EmployeeName,A.Remarks,
isnull(A.BFGJJ,0.00) BFGJJ,
isnull(A.BFGZ,0.00) BFGZ,
isnull(A.BLGZ,0.00) BLGZ,
isnull(A.CTF,0.00) CTF,
isnull(A.DTF,0.00) DTF,
isnull(A.FTF,0.00) FTF,
isnull(A.GHF,0.00) GHF,
isnull(A.GJJ,0.00) GJJ,
isnull(A.GTS,0.00) GTS,
isnull(A.GWF,0.00) GWF,
isnull(A.JBGZ,0.00) JBGZ,
isnull(A.JiangJ,0.00) JiangJ,
isnull(A.JZZYBF,0.00) JZZYBF,
isnull(A.KCBJ,0.00) KCBJ,
isnull(A.MTF,0.00) MTF,
isnull(A.QT,0.00) QT,
isnull(A.QTE,0.00) QTE,
isnull(A.QTY,0.00) QTY,
isnull(A.SBJ,0.00) SBJ,
isnull(A.Total,0.00) Total,
isnull(A.TotalOne,0.00) TotalOne,
isnull(A.TotalTwo,0.00) TotalTwo,
isnull(A.YBJ,0.00) YBJ,
isnull(A.YLJ,0.00) YLJ
,c.DeptName as DeptWprkName
,Substring(b.ReportMonth, 1, 4) + '年'
+ Substring(b.ReportMonth, 5, 2) + '月'
AS ReportMonth
FROM officedba.SalaryInfo a
left join officedba.SalaryReport b on a.ReprotNo=b.ReprotNo
left join officedba.DeptInfo c on b.DeptID=c.ID

从DB灌值到DataTable时,字段值为NULL时报错相关信息;的更多相关文章

  1. 配置python+mod_wsgi+apache 时 在浏览器中访问服务器时报错:Invalid HTTP_HOST header: &#39;XXXXX&#39;. You may need to add u&#39;XXXXX&#39; to ALLOWED_HOSTS,在setting.py中添加‘*”无效的原因

    配置python+mod_wsgi+apache 时 在浏览器中访问服务器时报错:Invalid HTTP_HOST header: 'XXXXX'. You may need to add u'XX ...

  2. rebuild online时意外中断 再次重建时报错解决方法

    rebuild online时意外中断 再次重建时报错 SQL> alter index PARTY.IDX_CM_INDIV_CUSTOMER_4 rebuild online; alter ...

  3. 因DataTable的字段值为DBNull引发的异常

    1 问题重现 (1)新建项目DBNullExp.项目属性为"控制台应用程序": (2)在项目下新建数据集Schools(数据集文件的后缀名为.xsd): watermark/2/t ...

  4. laravel中db获取某个数据的具体字段值:

    $helpfriend = DB::connection('luckyrecord')->table($luckyrecord)->where('id', $luckyrecordid)- ...

  5. fastadmin 列表展示时字段值截取

    {field: '字段名', title: __('lang中的语言名'),formatter:function(value,row,index){ value=value?value:''; var ...

  6. C# 调用 C++ 的 DLL 返回值为 bool 时,值混乱

    现象:C++ 导出函数的返回值为 false,C# 调用该函数获取的返回值却为 true . 原因:C++ 导出函数返回 false 时,采取的方式是: 将 C# 定义的用来接收返回值的 bool 所 ...

  7. mongoDB 批量更改数据,某个字段值等于另一个字段值

    由于mongodb数据库类似js的写法,所以即使数据库中新的列不存在也会自动创建 db.hospital.find().forEach( function(item){ db.hospital.upd ...

  8. Sql 查询结果 根据某个字段值 变更另外一个字段值 case when

    SELECT CASE THEN '*******' ELSE Plate END AS Plate, CarType FROM Cars;

  9. DSO激活时,生成主数据SID时报错:原因,主数据允许小写字母没有勾上

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

随机推荐

  1. 如何获取EntityManager

    1.在容器内部使用,使用@PersistenceContext 来注入.@PersistenceContextprivate EntityManager em;TAG================= ...

  2. JS表单学习笔记(思维导图)

    导图

  3. Day8 - Python网络编程 Socket编程

    Python之路,Day8 - Socket编程进阶   本节内容: Socket语法及相关 SocketServer实现多并发 Socket语法及相关 socket概念 socket本质上就是在2台 ...

  4. cf479D Long Jumps

    D. Long Jumps time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  5. $ cd `dirname $0` 和PWD%/* shell变量的一些特殊用法

    在命令行状态下单纯执行 $ cd `dirname $0` 是毫无意义的.因为他返回当前路径的".". $0:当前Shell程序的文件名dirname $0,获取当前Shell程序 ...

  6. Eclipse rap 富客户端开发总结(12) :Rap 优化之组件的销毁

    一.概述      经过几个月的rap 项目实战,总结了一些小经验,在这里总结一下,希望对大家有所帮助. 二.销毁的处理       相信学习rap 的同学都知道,swt 中提供了许多的组件,像lab ...

  7. js 闭包的用法详解

    一.闭包 实现可重用的局部变量,且保护其不受污染的机制. 外层函数包裹受保护的变量和内层函数. 内层函数专门负责操作外层函数的局部变量. 将内层函数返回到外层函数外部,反复调用. 二.作用域 子函数会 ...

  8. drbd(四):drbd多节点(drbd9)

    1.drbd多节点简介 在drbd9以前,drbd一直只能配置两个节点,要么是primary/secondary,要么是primary/primary.虽然在这些版本上也能配置第三个节点实现三路节点的 ...

  9. Linux/Windows远程桌面

    WINDOWS远程连接LINUX配置(LINUX VNC Server配置):   1.查看本机是否有安装vnc(centOS5默认有安装vnc) rpm -q vnc vnc-server 如果显示 ...

  10. TabBarController和其他view无法建立Relationship segue的原因

    拖拽怎么也没有那个出现,最后看sourcecode发现是那个那个viewcrontroler的XML 元素不是TabBarController.在Sourcecode里面改了一下,解决了这个问题. 总 ...