C# 给DataTable去重

using System;
using System.Data;

namespace DelegateTest
{
    public class Program
    {
        public static void Main(string[] args)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("ID",typeof(string));
            dt.Columns.Add("Name",typeof(string));
            DataRow dr1 = dt.NewRow();
            dr1[0] = "1001";
            dr1[1] = "张三";
            dt.Rows.Add(dr1);

            DataRow dr2 = dt.NewRow();
            dr2[0] = "1001";
            dr2[1] = "张三";
            dt.Rows.Add(dr2);

            foreach (DataRow dr in dt.Rows)
            {
                Console.WriteLine(dr[0]+"\t"+dr[1]);
            }

            Console.WriteLine("------------------------------------");

            DataTable dt2 = dt.DefaultView.ToTable(true,"ID","Name");

            foreach (DataRow dr in dt2.Rows)
            {
                Console.WriteLine(dr[0] + "\t" + dr[1]);
            }

        } 
    }
}

 

C# 给DataTable去重

上一篇:C# 获取一个文件的MD5值


下一篇:C# Base64加解密