某些数据丢失使用数据表和LINQ导出到Excel [英] Some data is missing in the Export to Excel using DataTable and Linq
问题描述
我出口三个单独的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屋!