获取不同版本的DataRow

    技术2022-05-11  59

    //获取不同版本的DataRowusing System;using System.IO;using System.Text;using System.Diagnostics;using System.Threading;using System.Collections;using System.Data;using System.Xml;using System.Management;using System.Net;

    namespace Zhzuo{ class ZZConsole {  [STAThread]  static void Main(string[] args)  {    DataSet ds = new DataSet();   CreatDataSetSchema(ds);   InitData(ds);   DataRow drdel = ds.Tables["Hosts"].Rows[0];   drdel.Delete();   Console.WriteLine(drdel.HasVersion(DataRowVersion.Default).ToString());   foreach(DataRow dr in ds.Tables["Hosts"].GetChanges(DataRowState.Deleted).Rows)   {    //if(dr.HasVersion(DataRowVersion.Current))    //{     Console.WriteLine((string)dr["HId"]);     Console.WriteLine(dr["IsLocal",DataRowVersion.Original].ToString());    //}   }   Console.WriteLine("end");   Console.ReadLine();  }  //初始化数据集结构  private static void CreatDataSetSchema(DataSet ds)  {   DataTable dt = new DataTable("Hosts");   DataColumn dc = new DataColumn("HId",typeof(String));   dt.Columns.Add(dc);   dc = new DataColumn("IsLocal",typeof(Boolean));   dt.Columns.Add(dc);   ds.Tables.Add(dt);  }  //加入数据  private static void InitData(DataSet ds)  {   DataRow hostsRow = ds.Tables["Hosts"].NewRow();   hostsRow["HId"] = "192.192.132.229";   hostsRow["IsLocal"] = true;   ds.Tables["Hosts"].Rows.Add(hostsRow);

       hostsRow = ds.Tables["Hosts"].NewRow();   hostsRow["HId"] = "192.192.132.231";   hostsRow["IsLocal"] = false;   ds.Tables["Hosts"].Rows.Add(hostsRow);

       hostsRow = ds.Tables["Hosts"].NewRow();   hostsRow["HId"] = "192.192.132.233";   hostsRow["IsLocal"] = false;   ds.Tables["Hosts"].Rows.Add(hostsRow);  } } }


    最新回复(0)