Home > Net >  C # two datatable contrast, there is update, there is no insert!
C # two datatable contrast, there is update, there is no insert!

Time:03-06

Two datatable in the following code (dt1 dt2), correlation code, ver two columns, if use dt2. There's a name to update the dt1. The name, there is no insert data into dt1, like the merge of SQL SERVER, which requires not cycle

 DataTable dt1=new DataTable (); 

DataColumn code=new DataColumn (" code ", typeof (string));
DataColumn ver=new DataColumn (" ver ", typeof (string));
DataColumn name=new DataColumn (" name ", typeof (string));
Dt1. Columns. The Add (code);
Dt1. Columns. The Add (ver);
Dt1. Columns. The Add (name);

Dt1. Rows. The Add (new object [] {' 1 ', '1', "zhang SAN"});//add the line
Dt1. Rows. The Add (new object [] {' 2 ', '1', "a1"});//add the line
Dt1. Rows. The Add (new object [] {' 3 ', '1', "a2"});//add the line

//for (int I=0; I & lt;=1000000; I++)
//{
//dt1. Rows. The Add (new object [] {i.T oString (), "zhang SAN" + i.T oString ()});//add the line

//}

The DataTable dt2=new DataTable ();

DataColumn code1=new DataColumn (" code ", typeof (string));
DataColumn ver1=new DataColumn (" ver ", typeof (string));
DataColumn name1=new DataColumn (" name ", typeof (string));
Dt2. Columns. The Add (code1);
Dt2. Columns. The Add (ver1);
Dt2. Columns. The Add (name1);

Dt2. Rows. The Add (new object [] {' 1 ', '1', "zhang SAN 1}");//add the line
Dt2. Rows. The Add (new object [] {' 2 ', '1', "222"});//add the line
Dt2. Rows. The Add (new object [] {' 3 ', '1', "333"});//add the line

//for (int I=0; I & lt;=100000; I++)
//{
//dt2. Rows. The Add (new object [] {i.T oString (), "zhang SAN's 888 + i.T oString ()});//add the line

//}
Dt2. Rows. The Add (new object [] {' 5 ', '1', "333"});//add the line
Dt2. Rows. The Add (new object [] {' 6 ', '1', "333"});//add the line
  •  Tags:  
  • C#
  • Related