某些数据丢失使用数据表和LINQ导出到Excel [英] Some data is missing in the Export to Excel using DataTable and Linq

查看:159
本文介绍了某些数据丢失使用数据表和LINQ导出到Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我出口三个单独的XL文件的工作表,但我在第二个 DataTable中缺少某些用户数据教育详情表)和第三数据表 Employeement详情表)。

I am exporting three worked sheet in single XL file, but I am missing some user data in the second DataTable (Education Details sheet) and third DataTable (Employeement Details sheet).

教育详情表是一些用户不存在,但用户呈现一个 Employeement详情表。用户电子邮件ID的是有三个数据库表。

The Education Details sheet is some users are not there, but an Employeement Details sheet that users are showing. User Email Id's is there all three Database Tables.

    DataSe ds = new DataSet();
    DataTable dt = new DataTable("Registration Details");
    DataTable dt1 = new DataTable("Education Details");
    DataTable dt2 = new DataTable("Employeement Details");


    dt = bl.Get_Registrationdetailsbydate(bo);
    gv_Regdetails.DataSource = dt;
    gv_Regdetails.DataBind();
    dt1 = bl.Get_Registrationdetailsbydate1(bo);
    dt2 = bl.Get_Registrationdetailsbydate2(bo);
    DataTable filteredEducation = dt1.AsEnumerable()
          .Where(x => dt.AsEnumerable()
          .Any(z => z.Field<string>("Email").Trim() == x.Field<string>("Email").Trim()))
          .CopyToDataTable();
    DataTable filteredEmployee = dt2.AsEnumerable()
          .Where(x => dt.AsEnumerable()
          .Any(z => z.Field<string>("Email").Trim() == x.Field<string>("Email").Trim()))
          .CopyToDataTable();

    dt.TableName = "Registration Details";
    filteredEducation.TableName = "Education Details";
    filteredEmployee.TableName = "Employeement Details";
    ds.Tables.Add(dt);
    ds.Tables.Add(filteredEducation);
    ds.Tables.Add(filteredEmployee);
    ExcelHelper.ToExcel(ds, "DangoteUsers.xls", Page.Response);

我做了第一个数据表用户结果的基础电子邮件,然后填写第二个数据表首次数据表 电子邮件标识的详细用户群。同就业详情。在第一个 DataTable中的问题和第二数据表。我不返回数据表也。

I did result base on first DataTable users Email, then fill second DataTable detail users base on first DataTable Email id's. Same as Employment Details. The issue in first DataTable and second DataTable. I am not returning the DataTable also.

我指这个例子

推荐答案

我想在LINQ查询你的字符串比较是problem..your电子邮件地址可能有可能导致此问题有不同的情况。试试下面code

I think your string comparison in linq query is a problem..your email address might have different case which could have caused this issue. Try below code

DataTable filteredEducation = dt1.AsEnumerable()
          .Where(x => dt.AsEnumerable()
          .Any(z => z.Field<string>("Email").Trim().Equals(x.Field<string>("Email").Trim(),StringComparison.CurrentCultureIgnoreCase)))
          .CopyToDataTable();
    DataTable filteredEmployee = dt2.AsEnumerable()
          .Where(x => dt.AsEnumerable()
          .Any(z => z.Field<string>("Email").Trim().Equals(x.Field<string>("Email").Trim(),StringComparison.CurrentCultureIgnoreCase)))
          .CopyToDataTable();

这篇关于某些数据丢失使用数据表和LINQ导出到Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆