dataset 合并

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace merge
{
    class merge
    {
        static void Main(string[] args)
        {
            DataSet regularbooks = new DataSet("RegularBooks");
            DataSet bestsellers = new DataSet("BestSellers");

            DataTable regulartable = new DataTable("books");
            DataTable sellertable = new DataTable("books");

            DataColumn newcol = new DataColumn("ISBN",typeof(string));
            regulartable.Columns.Add(newcol);
            newcol = new DataColumn("Title", typeof(string));
            regulartable.Columns.Add(newcol);

            newcol = new DataColumn("ISBN", typeof(string));
            sellertable.Columns.Add(newcol);
            newcol = new DataColumn("Title", typeof(string));
            sellertable.Columns.Add(newcol);
            newcol = new DataColumn("WeekOnTop10", typeof(int));
            newcol.DefaultValue = 0;
            sellertable.Columns.Add(newcol);
 

            //add book to regular table
            DataRow newbook = regulartable.NewRow();
            newbook["ISBN"] = "154565555";
            newbook["Title"] = ".net compact framework";
            regulartable.Rows.Add(newbook);

          
            newbook = regulartable.NewRow();
            newbook["ISBN"] = "1524455";
            newbook["Title"] = "c#";
            regulartable.Rows.Add(newbook);

            //add book to seller table
            newbook = sellertable.NewRow();
            newbook["ISBN"] = "35446545";
            newbook["Title"] = "lucky man:a memoir";
            newbook["WeekOnTop10"] = 3;
            sellertable.Rows.Add(newbook);

            newbook = sellertable.NewRow();
            newbook["ISBN"] = "35446545";
            newbook["Title"] = "lucky man:a memoir";
            newbook["WeekOnTop10"] = 3;
            sellertable.Rows.Add(newbook);

            regularbooks.Tables.Add(regulartable);
            bestsellers.Tables.Add(sellertable);

            regularbooks.Merge(bestsellers, true, MissingSchemaAction.Add); //合并语句
            foreach (DataRow book in regulartable.Rows)
            {
                Console.WriteLine("{0},ISBN:{1},Weeks On Top 10:{2}",book["Title"].ToString(),book["ISBN"].ToString(),(int)book["WeekOnTop10"]);
            }
        }
    }
}