我有一个数据表,将由用户修改。 我想确定数据库中记录的变化。
我看到这样做的最佳方法是在作出任何改动之前复制这一数据,并核实用户节省表格时发生的变化。
问题是,我是否使用我的可言。 Clone()或我的DataTable.Copy(),数据总是相同。 因此,我猜测他们只是在表格中提出参考。
你们如何处理这一问题?
我有一个数据表,将由用户修改。 我想确定数据库中记录的变化。
我看到这样做的最佳方法是在作出任何改动之前复制这一数据,并核实用户节省表格时发生的变化。
问题是,我是否使用我的可言。 Clone()或我的DataTable.Copy(),数据总是相同。 因此,我猜测他们只是在表格中提出参考。
你们如何处理这一问题?
Try the DataSet.HasChanges
。 如果对数据集有任何改动,如删除或添加行文、改换行等,将告诉你。
http://msdn.microsoft.com/en-us/library/system.dataset.getchanges.aspx”rel=“nofollow”>DataSet.GetChanges
,以了解情况的变化。 这种方法将退还一份改动。
For example, you could say:
private void VerifyChanges(DataSet dataSet)
{
if(!dataSet.HasChanges(DataRowState.Modified)) return;
var changedDataSet = dataSet.GetChanges(DataRowState.Modified);
//... do the tracking or whatever else you want here.
}
或者,如果你不想进行所有数据单的改动,而只是想从一个具体表格<>上改动:
private void VerifyChanges(DataSet dataSet, string tableName)
{
if(!dataSet.HasChanges(DataRowState.Modified)) return;
var changedTable = dataSet
.Tables[tableName]
.GetChanges(DataRowState.Modified);
//... do the tracking or whatever else you want here.
}
最后,为了将原有数值从修改后的数据单中删除,你可以编码:
row[columnIndex, DataRowVersion.Original]
海事组织的快速和不附带方式是serialize
然后是deserialize
the DataTable。 如果你决定使用Xml序列化,则确保首先在数据表内公布数据。
Consider use of DataTable.GetChanges Method (DataRowState). This method returns a new data table with the rows that were changed.
例:
DataTable changeTable = table.GetChanges(DataRowState.Modified);
如果有这个表格,你可以将每行一行与另一个数据表进行比较。
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...
Since I cannot order my dictionary, what is the best way of going about taking key value pairs and also maintaing an index?
Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...