本文整理汇总了C#中System.Data.DataRow.CopyValuesToRow方法的典型用法代码示例。如果您正苦于以下问题:C# DataRow.CopyValuesToRow方法的具体用法?C# DataRow.CopyValuesToRow怎么用?C# DataRow.CopyValuesToRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.DataRow
的用法示例。
在下文中一共展示了DataRow.CopyValuesToRow方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddChangedRow
private void AddChangedRow (Hashtable addedRows, DataTable copyTable, DataRow row)
{
if (addedRows.ContainsKey (row))
return;
foreach (DataRelation relation in row.Table.ParentRelations) {
DataRow parent = ( row.RowState != DataRowState.Deleted ?
row.GetParentRow (relation) :
row.GetParentRow (relation, DataRowVersion.Original)
);
if (parent == null)
continue;
// add the parent row
DataTable parentCopyTable = copyTable.DataSet.Tables [parent.Table.TableName];
AddChangedRow (addedRows, parentCopyTable, parent);
}
// add the current row
DataRow newRow = copyTable.NewNotInitializedRow ();
copyTable.Rows.AddInternal (newRow);
// Don't check for ReadOnly, when cloning data to new uninitialized row.
row.CopyValuesToRow (newRow, false);
newRow.XmlRowID = row.XmlRowID;
addedRows.Add (row, row);
}
示例2: MergeRow
// merge a row into a target table.
private static void MergeRow(DataTable targetTable, DataRow row, bool preserveChanges)
{
DataColumnCollection columns = row.Table.Columns;
DataColumn[] primaryKeys = targetTable.PrimaryKey;
DataRow targetRow = null;
DataRowVersion version = DataRowVersion.Default;
if (row.RowState == DataRowState.Deleted)
version = DataRowVersion.Original;
if (primaryKeys != null && primaryKeys.Length > 0) // if there are any primary key.
{
// initiate an array that has the values of the primary keys.
object[] keyValues = new object[primaryKeys.Length];
for (int j = 0; j < keyValues.Length; j++)
{
keyValues[j] = row[primaryKeys[j].ColumnName, version];
}
// find the row in the target table.
targetRow = targetTable.Rows.Find(keyValues, DataViewRowState.OriginalRows);
if (targetRow == null)
targetRow = targetTable.Rows.Find(keyValues);
}
// row doesn't exist in target table, or there are no primary keys.
// create new row and copy values from source row to the new row.
if (targetRow == null)
{
DataRow newRow = targetTable.NewNotInitializedRow();
row.CopyValuesToRow(newRow);
targetTable.Rows.AddInternal (newRow);
}
// row exists in target table, and presere changes is false -
// change the values of the target row to the values of the source row.
else if (!preserveChanges)
{
row.CopyValuesToRow(targetRow);
}
}
示例3: AddChangedRow
private void AddChangedRow (Hashtable addedRows, DataTable copyTable, DataRow row)
{
if (addedRows.ContainsKey (row)) return;
foreach (DataRelation relation in row.Table.ParentRelations) {
DataRow parent = row.GetParentRow (relation);
if (parent == null)
continue;
// add the parent row
DataTable parentCopyTable = copyTable.DataSet.Tables [parent.Table.TableName];
AddChangedRow (addedRows, parentCopyTable, parent);
}
// add the current row
DataRow newRow = copyTable.NewNotInitializedRow();
copyTable.Rows.AddInternal(newRow);
row.CopyValuesToRow (newRow);
newRow.XmlRowID = row.XmlRowID;
addedRows.Add (row, row);
}