从DB灌值到DataTable时,字段值为NULL时报错相关信息;
报错信息:
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时报错相关信息;的更多相关文章
- 配置python+mod_wsgi+apache 时 在浏览器中访问服务器时报错:Invalid HTTP_HOST header: 'XXXXX'. You may need to add u'XXXXX' to ALLOWED_HOSTS,在setting.py中添加‘*”无效的原因
配置python+mod_wsgi+apache 时 在浏览器中访问服务器时报错:Invalid HTTP_HOST header: 'XXXXX'. You may need to add u'XX ...
- rebuild online时意外中断 再次重建时报错解决方法
rebuild online时意外中断 再次重建时报错 SQL> alter index PARTY.IDX_CM_INDIV_CUSTOMER_4 rebuild online; alter ...
- 因DataTable的字段值为DBNull引发的异常
1 问题重现 (1)新建项目DBNullExp.项目属性为"控制台应用程序": (2)在项目下新建数据集Schools(数据集文件的后缀名为.xsd): watermark/2/t ...
- laravel中db获取某个数据的具体字段值:
$helpfriend = DB::connection('luckyrecord')->table($luckyrecord)->where('id', $luckyrecordid)- ...
- fastadmin 列表展示时字段值截取
{field: '字段名', title: __('lang中的语言名'),formatter:function(value,row,index){ value=value?value:''; var ...
- Json转换值类型字段为空字符串时报错问题
问题 在写Webservices时,碰到的问题. 定义的类 public class User { public string sID { get; set; } public int? iAge { ...
- C# 调用 C++ 的 DLL 返回值为 bool 时,值混乱
现象:C++ 导出函数的返回值为 false,C# 调用该函数获取的返回值却为 true . 原因:C++ 导出函数返回 false 时,采取的方式是: 将 C# 定义的用来接收返回值的 bool 所 ...
- mongoDB 批量更改数据,某个字段值等于另一个字段值
由于mongodb数据库类似js的写法,所以即使数据库中新的列不存在也会自动创建 db.hospital.find().forEach( function(item){ db.hospital.upd ...
- Sql 查询结果 根据某个字段值 变更另外一个字段值 case when
SELECT CASE THEN '*******' ELSE Plate END AS Plate, CarType FROM Cars;
随机推荐
- jQuery实现抖动效果
//抖动效果 //intShakes:抖动次数:intDistance:抖动左右距离:intDuration:持续时间 jQuery.fn.shake = function (intShakes, i ...
- zend 快捷键
Ctrl+1 快速修复(最经典的快捷键,就不用多说了)Ctrl+D: 删除当前行Ctrl+Alt+↓ 复制当前行到下一行(复制增加)Ctrl+Alt+↑ 复制当前行到上一行(复制增加)Alt+↓ 当前 ...
- Android之使用Android-AQuery异步加载图片(一)
第一节:转载地址(http://www.cnblogs.com/lee0oo0/archive/2012/10/25/2738299.html) // 必须实现AQuery这个类 AQuery aq ...
- kindeditor编辑器的使用
KindEditor是一款用Javascript编写的开源在线HTML编辑器,主要用户是让用户在网站上获得可见即可得的编辑效果,开发人员可以用 KindEditor 把传统的多行文本输入框(texta ...
- Android_getSystemService (demo_testNet)
今天主要通过一个案例来看下我们的Android 获取系统服务的问题. 我们通常能够看见登录QQ后如果没有网络的状态的时候,它会告诉你一句话:您进入了没有网络的异次元或者是什么网络连接错误等等.Andr ...
- 关于ES6的数组字符串方法
注:ES6的一些新属性会显示语法错误,不过不会影响效果,在Languages里面也可以调: let:用来定义变量 特点:只能在代码块里面使用,let拥有块级作用域;并且let不允许重复声明;比如: v ...
- C语课设心得分享(三)
调试. 以前咱们写课后习题,一般也不需要使用调试,如果程序编译error,根据错误信息就可以改好:如果是结果错误,那么在稿纸上过几遍基本也可以得出结果. 但咱们这个课设比较大,就需要很多调试的过程,尤 ...
- Scanner键盘录入(欢迎交流)
一:练习 判断一个字符串是否是对称字符串,例如"abc"不是对称字符串,"aba"."abba"."aaa"." ...
- JavaScript小功能
1. JS判断是否为一个有效日期 1 2 3 4 function check(date){ return (new Date(date).getDate()==date.substring( ...
- Centos6.7 python2.6升级到python2.7
查看python版本: #python -V Python 2.6.6 1.下载python 2.7.3 #wget http://python.org/ftp/python/2.7.3/Python ...