c# - Some data is missing in the Export to Excel using DataTable and Linq -
i exporting 3 worked sheet in single xl file, missing user data in second datatable (education details sheet) , third datatable (employeement details sheet).
the education details sheet users not there, employeement details sheet users showing. user email id's there 3 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); i did result base on first datatable users email, fill second datatable detail users base on first datatable email id's. same employment details. issue in first datatable , second datatable. not returning datatable also.
i refer this example
i think string comparison in linq query problem..your email address might have different case have caused 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();
Comments
Post a Comment