本文整理汇总了C#中System.Data.DataRow.IndexFromVersion方法的典型用法代码示例。如果您正苦于以下问题:C# DataRow.IndexFromVersion方法的具体用法?C# DataRow.IndexFromVersion怎么用?C# DataRow.IndexFromVersion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.DataRow
的用法示例。
在下文中一共展示了DataRow.IndexFromVersion方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportRow
/// <summary>
/// Copies a DataRow into a DataTable, preserving any
/// property settings, as well as original and current values.
/// </summary>
public void ImportRow (DataRow row)
{
if (row.RowState == DataRowState.Detached)
return;
DataRow newRow = NewNotInitializedRow ();
int original = -1;
if (row.HasVersion (DataRowVersion.Original)) {
original = row.IndexFromVersion (DataRowVersion.Original);
newRow.Original = RecordCache.NewRecord ();
RecordCache.CopyRecord (row.Table, original, newRow.Original);
}
if (row.HasVersion (DataRowVersion.Current)) {
int current = row.IndexFromVersion (DataRowVersion.Current);
if (current == original) {
newRow.Current = newRow.Original;
} else {
newRow.Current = RecordCache.NewRecord ();
RecordCache.CopyRecord (row.Table, current, newRow.Current);
}
}
//Import the row only if RowState is not detached
//Validation for Deleted Rows happens during Accept/RejectChanges
if (row.RowState != DataRowState.Deleted)
newRow.Validate ();
else
AddRowToIndexes (newRow);
Rows.AddInternal(newRow);
if (row.HasErrors)
row.CopyErrors (newRow);
}
示例2: SetParentRow
/// <summary>
/// Sets the parent row of a DataRow with specified new parent DataRow and
/// DataRelation.
/// </summary>
public void SetParentRow (DataRow parentRow, DataRelation relation)
{
if (_table == null || parentRow.Table == null)
throw new RowNotInTableException("This row has been removed from a table and does not have any data. BeginEdit() will allow creation of new data in this row.");
if (parentRow != null && _table.DataSet != parentRow.Table.DataSet)
throw new ArgumentException();
if (RowState == DataRowState.Detached && !HasVersion(DataRowVersion.Default)) {
// the row should have default data to access, i.e. we can do this for the newly created row, but not for the row once deleted from the table
throw new RowNotInTableException("This row has been removed from a table and does not have any data. BeginEdit() will allow creation of new data in this row.");
}
BeginEdit();
IEnumerable relations;
if (relation == null) {
relations = _table.ParentRelations;
}
else {
relations = new DataRelation[] { relation };
}
foreach (DataRelation rel in relations)
{
DataColumn[] childCols = rel.ChildColumns;
DataColumn[] parentCols = rel.ParentColumns;
for (int i = 0; i < parentCols.Length; i++)
{
if (parentRow == null) {
childCols[i].DataContainer[Proposed] = DBNull.Value;
}
else {
int defaultIdx = parentRow.IndexFromVersion(DataRowVersion.Default);
childCols[i].DataContainer.CopyValue(parentCols[i].DataContainer,defaultIdx,Proposed);
}
}
}
EndEdit();
}
示例3: RowsExist
internal bool RowsExist (DataColumn [] columns, DataColumn [] relatedColumns, DataRow row)
{
int curIndex = row.IndexFromVersion (DataRowVersion.Default);
int tmpRecord = RecordCache.NewRecord ();
try {
for (int i = 0; i < relatedColumns.Length; i++)
// according to MSDN: the DataType value for both columns must be identical.
columns [i].DataContainer.CopyValue (relatedColumns [i].DataContainer, curIndex, tmpRecord);
return RowsExist (columns, tmpRecord);
} finally {
RecordCache.DisposeRecord (tmpRecord);
}
}
示例4: ImportRow
/// <summary>
/// Copies a DataRow into a DataTable, preserving any
/// property settings, as well as original and current values.
/// </summary>
public void ImportRow (DataRow row)
{
DataRow newRow = NewNotInitializedRow();
int original = -1;
if (row.HasVersion(DataRowVersion.Original)) {
original = row.IndexFromVersion(DataRowVersion.Original);
newRow.Original = RecordCache.NewRecord();
RecordCache.CopyRecord(row.Table,original,newRow.Original);
}
if (row.HasVersion(DataRowVersion.Current)) {
int current = row.IndexFromVersion(DataRowVersion.Current);
if (current == original)
newRow.Current = newRow.Original;
else {
newRow.Current = RecordCache.NewRecord();
RecordCache.CopyRecord(row.Table,current,newRow.Current);
}
}
if (EnforceConstraints)
// we have to check that the new row doesn't colide with existing row
Rows.ValidateDataRowInternal(newRow);
Rows.AddInternal(newRow);
if (row.HasErrors) {
row.CopyErrors(newRow);
}
}