问题描述
我正在单个XL文件中导出三张工作表,但是在第二个 DataTable
(教育详细信息
sheet)和第三个 DataTable
( Employeement Details
sheet)。
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 Details
用户显示的工作表。用户电子邮件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
电子邮件
,然后填写第二个 DataTable
详细用户基于第一个 DataTable
电子邮件
id。与就业详情
相同。第一个 DataTable
和第二个 DataTable
中的问题。我没有返回 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查询中的字符串比较是一个问题。你的电子邮件地址可能有不同的情况,可能导致这个问题。尝试以下代码
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();
这篇关于使用DataTable和Linq在“导出到Excel”中缺少一些数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!