如何获取一个DataTable中RowState为Deleted的行?

reformer 2005-06-24 09:07:16
如题!

一个DataTable中,我删除了一些行,现在我要获取其已删除的行的信息,有什么办法?
...全文
224 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovefootball 2005-06-24
  • 打赏
  • 举报
回复
DataSet ds = this.dataSet1.GetChanges(DataRowState.Deleted);

for( int i = 0 ; i < ds.Table[0].Rows.Count ; i ++ )
{}
zhongwanli 2005-06-24
  • 打赏
  • 举报
回复
一楼的方法,

注意: 如需要读取删除行的数据请用索引访问

for( int i = 0 ; i < table.Rows.Count ; i ++ )
{}

不要使用
foreach( DataRow dr in table.Rows )
{}
ghchen 2005-06-24
  • 打赏
  • 举报
回复
GetChanges
fengfangfang 2005-06-24
  • 打赏
  • 举报
回复
private void ProcessDeletes(DataTable myDataTable, OleDbDataAdapter myDataAdapter)
{
DataTable xDataTable = myDataTable.GetChanges(DataRowState.Deleted);

// Check the DataTable for errors.
if (xDataTable.HasErrors)
{
// Insert code to resolve errors.
}

// After fixing errors, update the database with the DataAdapter
myDataAdapter.Update(xDataTable);
}
marvelstack 2005-06-24
  • 打赏
  • 举报
回复
//获取不同版本的DataRow
using 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);
}
}

}
qsoo 2005-06-24
  • 打赏
  • 举报
回复
帮你顶下
zhanglizhao 2005-06-24
  • 打赏
  • 举报
回复
DataSet ds = this.dataSet1.GetChanges(DataRowState.Deleted);

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧