本文整理匯總了C#中System.Data.DataTable.NewNotInitializedRow方法的典型用法代碼示例。如果您正苦於以下問題:C# DataTable.NewNotInitializedRow方法的具體用法?C# DataTable.NewNotInitializedRow怎麽用?C# DataTable.NewNotInitializedRow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Data.DataTable
的用法示例。
在下文中一共展示了DataTable.NewNotInitializedRow方法的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);
}