DataTable 修改行的指定值NE

DataTable 修改行的指定值

    public DataTable DepartmentDiseaseCharts()
        {
            DataTable dt = new DataTable();
            using (ServiceController.EF.MSISEntities context = new ServiceController.EF.MSISEntities())
            {
                context.Database.CommandTimeout = 9999;
                string theCondition1 = "";
                string theSQL = String.Format(@"WITH T AS (
SELECT DISTINCT DepartmentCode FROM dbo.Disease WHERE  DepartmentCode !='')
SELECT COUNT(Id) AS DiseaseCount,D.DepartmentCode FROM dbo.Disease D INNER  JOIN T ON T.DepartmentCode = D.DepartmentCode
GROUP BY D.DepartmentCode", theCondition1);
                var testCommand = new SqlCommand(theSQL, (SqlConnection)context.Database.Connection);
                SqlDataAdapter adapterd = new SqlDataAdapter(testCommand);
                adapterd.Fill(dt);

            }
//前边只有两列,添加一列DepartmentName
            dt.Columns.Add("DepartmentName", typeof(string)); //数据类型为 文本
            for (int i = 0; i < dt.Rows.Count-1; i++)
            {
                string code = dt.Rows[i].ItemArray[1].ToString();

                var list = MDMDataService.GetOrgInfoByWord(code).Select(
              t =>
              new Department()
              {
                  Code = t.SubOrgCode,
                  Name = t.SubOrgName,
                  OrgName = t.SubOrgName,
                  ParentOrgCode = t.ParentOrgCode,
                  ParentOrgName = t.ParentOrgName
              }).ToList();
//修改制定行的第三个字段,然后赋值
                DataRow drEmployee = dt.Rows[i];
                drEmployee.BeginEdit();
                drEmployee["DepartmentName"] = string.IsNullOrEmpty(list[0].Name.ToString())?"暂无": list[0].Name.ToString();
                drEmployee.EndEdit();

            }

            return dt;
        }

前台显示打印出来的结果
这里写图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值