// First, add system. Data. datasetextensions;
Dataset DS = New Dataset ();
DS. locale = Cultureinfo. invariantculture;
Filldataset (DS );
Datatable contacttable=DS. Tables ["Contact"];
// Create two tables.
Ienumerable < Datarow > Query1 = From contact In Contacttable. asenumerable ()
Where Contact. Field < String > ( " Title " ) = " Ms. "
Select contact;
Ienumerable < Datarow > Query2 = From contact In Contacttable. asenumerable ()
Where Contact. Field < String > ( " Firstname " ) = " Sandra "
Select contact;
Datatable contacts1=Query1.copytodatatable ();
Datatable contacts2=Query2.copytodatatable ();
//Find the intersection of the two tables. Calculate the intersection using intersect/Union (Union)/Except T (difference set)
VaR contacts=Contacts1.asenumerable (). Intersect (contacts2.asenumerable (),
Datarowcomparer. Default );
Console. writeline ( " Intersection of contacts tables " );
Foreach (Datarow row In Contacts)
{
Console. writeline ( " ID: {0} {1} {2} {3} " ,
Row [ " Contactid " ], Row [ " Title " ], Row [ " Firstname " ], Row [ " Lastname " ]);
}
The above is the msdnCodeThe following is your own code, which is relatively concise:
Dbhelpersql. connectionstring = Strsiteconnection;
Datatable dtblsitetable = Dbhelpersql. tquery ( " Select * from " + Strtablename );
Ienumerable < Datarow > Querysite = From contact In Dtblsitetable. asenumerable () Select contact;
dbhelpersql. connectionstring = strmainconnection;
datatable dtblmaintable = dbhelpersql. tquery ( " select * from " + strtablename );
ienumerable datarow > querymain = from contact in dtblmaintable. asenumerable () Select contact;
VaR enumerable0000t=Querysite. copytodatatable (). asenumerable (). Cannot T (querymain. copytodatatable (). asenumerable (), datarowcomparer. Default );
Datatable dtblexcept=Enumerableexcept. copytodatatable ();//Dtblexcept is the data table of the difference.