Home > Net >  VB.net take intersection between two or more DataTable
VB.net take intersection between two or more DataTable

Time:10-11

Everyone a great god, and I'm a pure white, consult between two or more DataTable get intersection and deposit the intersection into a new DataTable, who can give some example code, thank you very much!!!!!!

CodePudding user response:

The DataTable dt1=new DataTable ();
Dt1. Columns. The Add (" ID ", typeof (int));
Dt1. Columns. The Add (" Name ", typeof (string));
Dt1. PrimaryKey=new DataColumn [] {dt1. Columns [0]}.
Dt1. Rows. The Add (1, "Age");
Dt1. Rows. The Add (2, "Apple");
Dt1. Rows. The Add (3, "Orange");

The DataTable dt2=new DataTable ();
Dt2. Columns. The Add (" ID ", typeof (int));
Dt2. Columns. The Add (" Price ", typeof (decimal));
Dt2. PrimaryKey=new DataColumn [] {dt2. Columns [0]}.
Dt2. Rows. The Add (1, 10);
//dt2. Rows. The Add (2, 6);
Dt2. Rows. The Add (3, 7);

The DataTable dt3=dt1. Copy ();
Dt3. Merge (dt2);

CodePudding user response:

Top a

CodePudding user response:

The merge can fill several parameters in it? Only two merge?

CodePudding user response:

The merge can fill several parameters in it? If there are multiple, only two merge?

CodePudding user response:

reference 1st floor ManBOyyy response:
DataTable dt1=new DataTable ();
Dt1. Columns. The Add (" ID ", typeof (int));
Dt1. Columns. The Add (" Name ", typeof (string));
Dt1. PrimaryKey=new DataColumn [] {dt1. Columns [0]}.
Dt1. Rows. The Add (1, "Age");
Dt1. Rows. The Add (2, "Apple");
Dt1. Rows. The Add (3, "Orange");

The DataTable dt2=new DataTable ();
Dt2. Columns. The Add (" ID ", typeof (int));
Dt2. Columns. The Add (" Price ", typeof (decimal));
Dt2. PrimaryKey=new DataColumn [] {dt2. Columns [0]}.
Dt2. Rows. The Add (1, 10);
//dt2. Rows. The Add (2, 6);
Dt2. Rows. The Add (3, 7);

The DataTable dt3=dt1. Copy ();
Dt3. Merge (dt2);


If there are multiple, how to do? The merger of the two and two

CodePudding user response:

If multiple tatable no main foreign keys, just want to merge to the last, is this way
Dt3. Merge (dt2);
Dt3. Merge (dt4);
Dt3. Merge (dt5);
Dt3. Merge (dt6);

CodePudding user response:

refer to 6th floor ManBOyyy response:
if multiple tatable no main foreign key, just want to merge in the end, is this way
Dt3. Merge (dt2);
Dt3. Merge (dt4);
Dt3. Merge (dt5);
Dt3. Merge (dt6);


On the morning of the test for intersection is effective, not effective now,,,,

CodePudding user response:

The DataTable dt1=new DataTable ();
Dt1. Columns. The Add (" ID ", typeof (int));
Dt1. Columns. The Add (" Name ", typeof (string));
Dt1. Rows. The Add (1, "Age");
Dt1. Rows. The Add (2, "Apple");

The DataTable dt2=new DataTable ();
Dt2. Columns. The Add (" ID ", typeof (int));
Dt2. Columns. The Add (" Name ", typeof (string));
Dt2. Rows. The Add (1, "Age");
Dt2. Rows. The Add (2, "Apple");



The DataTable dt3=new DataTable ();
Dt3. Columns. The Add (" ID ", typeof (int));
Dt3. Columns. The Add (" Name ", typeof (string));
Dt3. Rows. The Add (1, "Age");
Dt3. Rows. The Add (2, "Apple");
Dtnew=dt1. Clone ();
Dtnew. Merge (dt1);
Dtnew. Merge (dt2);
Dtnew. Merge (dt3);
Dtnew. Merge (dt4);

CodePudding user response:

refer to 6th floor ManBOyyy response:
if multiple tatable no main foreign key, just want to merge in the end, is this way
Dt3. Merge (dt2);
Dt3. Merge (dt4);
Dt3. Merge (dt5);
Dt3. Merge (dt6);


On the morning of the test for intersection is effective, not effective now,,,,

refer to the eighth floor ManBOyyy response:
DataTable dt1=new DataTable ();
Dt1. Columns. The Add (" ID ", typeof (int));
Dt1. Columns. The Add (" Name ", typeof (string));
Dt1. Rows. The Add (1, "Age");
Dt1. Rows. The Add (2, "Apple");

The DataTable dt2=new DataTable ();
Dt2. Columns. The Add (" ID ", typeof (int));
Dt2. Columns. The Add (" Name ", typeof (string));
Dt2. Rows. The Add (1, "Age");
Dt2. Rows. The Add (2, "Apple");



The DataTable dt3=new DataTable ();
Dt3. Columns. The Add (" ID ", typeof (int));
Dt3. Columns. The Add (" Name ", typeof (string));
Dt3. Rows. The Add (1, "Age");
Dt3. Rows. The Add (2, "Apple");
Dtnew=dt1. Clone ();
Dtnew. Merge (dt1);
Dtnew. Merge (dt2);
Dtnew. Merge (dt3);
Dtnew. Merge (dt4);



My test is to merge now, not to their intersection, two of my table structure are all the same, only keep the same data

CodePudding user response:

An example screenshot,
  • Related