报错信息:

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: '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 ...

  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. Json转换值类型字段为空字符串时报错问题

    问题 在写Webservices时,碰到的问题. 定义的类 public class User { public string sID { get; set; } public int? iAge { ...

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

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

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

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

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

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

随机推荐

  1. js方法之间的调用之——传参方法

    在最近项目需求中发现,完成一些功能的时候总是要调很多结构类似的方法,写起来很繁琐,所以就想写一个“万能”方法,是的代码更简洁.即:把一个方法作为参数传给这个“万能”方法,让它去执行你给定的方法,就类似 ...

  2. JS动态获取数据

    JS访问数据,有实时获取数据的时候,请加上时间戳 如:'&stampflag=' + Math.round(new Date().getTime() / 1000); 因为有的浏览器(如IE9 ...

  3. django中自定义标签和过滤器

    想要实现自定义标签和过滤器需要进行准备工作: 准备(必需)工作: 1  在某个app下创建一个名为templatetags(必需,且包名不可变)的包.假设我们在名为polls的app下创建了一个tem ...

  4. solr 5.5.1安装并配置中文分词IKAnalyzer

    http://www.360doc.com/content/16/0623/17/5131531_570184594.shtml ——————————————————————————————————— ...

  5. sqlserver 加内置dll的使用内存

  6. Get the Uniqueid of Action Originate in the AMI

    [asterisk-users] Get the Uniqueid of Action Originate in the AMI Adolphe Cher-Aime acheraime at gmai ...

  7. 解决Linux c语言运行时候“段错误 (核心已转储)”问题-采用gdb 解决

    编译没有警告,没有错误,运行就打印 段错误 (核心已转储) 网上找了一下,都是各种问题,都推荐用gdb 调试解决,咱也来趁机学习gdb一下.   gcc+gdb)输入命令行 运行 sudo apt-g ...

  8. C#中TreeView与数据库绑定

    protected void CreateTreeView() { TreeNode rootNode = new TreeNode(); rootNode.Text = "全部" ...

  9. fedora 安装vmwear

    Fedora 13下安装后缀为bundle文件,网上的说法很多,最普遍的方法是: 你的登陆名为TEST那么就将要安装的文件放在TEST目录下,不要放到目录下的子目录上面,否则不能运行.然后执行 第一步 ...

  10. EasyUI Combobox设定默认值

    $(function () { $('#Select6').combobox({ onLoadSuccess: function () { var data = $('#Select6').combo ...