c# - Filtering on multiple DataTables with First DataTable -


i trying export database tables details multiple worksheets inside single excel file , got export working correct, issue multiple datatable filtering first datatable email id.

below c# code:

  protected void button1_click(object sender, eventargs e) {      dataset ds = new dataset();     datatable dt = new datatable("registration details");      datatable dt1 = new datatable("education details");      dt = bl.get_registrationdetailsbydate1(bo);      dt1 = bl.get_registrationdetailsbydate2(bo);      ds.tables.add(dt);      ds.tables.add(dt1);      excelhelper.toexcel(ds, "users.xls", page.response);     } 

i have 2 tables registration_table , education_table , have 2 datatable registration details , education details.

i need result base on email id's of first datatable(dt) first datatable emails id's users should come second datatable means education details based on email ids.

suppose below first datatable details.

sno    email            mobile        city   1     raj@gmail.com     123456789    hyderabad 

i need result of second datatable details below single users.

sno       email              education    1        raj@gmail.com       mba 

and using 2 stored procedures first getting registration details , second education details.

imho best approach @ database end itself, i.e. when fetch registration details based on details query education details too, if logic complicated rather simple tables have loop through registration datatable , pass email address parameter fetch education details. altough compilcated approach since have store emails in registration table , fetch education details.

foreach(datarow row in  dtregistration.rows) {     string email = row.field<string>("email");     //store in collection or comma separeted string , pass     //bl.get_registrationdetailsbydate2(bo); table. } 

if don't have huge data , fine current code on how both datatable populated let code , use linq filter education datatable this:-

datatable filterededucation = dteducation.asenumerable()              .where(x => dtregistration.asenumerable()                            .any(z => z.field<string>("email") == x.field<string>("email")))              .copytodatatable(); 

you have import system.linq namespace.

update:

finally button clcik handler should this:-

dt = bl.get_registrationdetailsbydate1(bo); dt1 = bl.get_registrationdetailsbydate2(bo); datatable filterededucation = dt1.asenumerable()                                  .where(x => dt.asenumerable()                            .any(z => z.field<string>("email") == x.field<string>("email")))                            .copytodatatable(); ds.tables.add(dt); ds.tables.add(filterededucation); excelhelper.toexcel(ds, "dangoteusers.xls", page.response);    

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -