system.data.datatable 中的 newrow()方法是怎么实现的?internal void InsertRow(DataRow row, int proposedID, int pos, bool fireEvent)
{
Exception deferredException = null;
bool flag;
if (row == null)
{
throw ExceptionBuilder.ArgumentNull("row");
}
if (row.Table != this)
{
throw ExceptionBuilder.RowAlreadyInOtherCollection();
}
if (row.rowID != -1)
{
throw ExceptionBuilder.RowAlreadyInTheCollection();
}
row.BeginEdit();
int tempRecord = row.tempRecord;
row.tempRecord = -1;
if (proposedID == -1)
{
proposedID = this.nextRowID;
}
if (flag = this.nextRowID <= proposedID)
{
this.nextRowID = proposedID + 1;
}
try
{
try
{
row.rowID = proposedID;
this.SetNewRecordWorker(row, tempRecord, DataRowAction.Add, false, pos, fireEvent, out deferredException);
}
catch
{
if (flag && (this.nextRowID == (proposedID + 1)))
{
this.nextRowID = proposedID;
}
row.rowID = -1;
row.tempRecord = tempRecord;
throw;
}
if (deferredException != null)
{
throw deferredException;
}
if (this.EnforceConstraints && !this.inLoad)
{
int count = this.columnCollection.Count;
for (int i = 0; i < count; i++)
{
DataColumn column = this.columnCollection[i];
if (column.Computed)
{
column.CheckColumnConstraint(row, DataRowAction.Add);
}
}
}
}
finally
{
row.ResetLastChangedColumn();
}
}上面是代码 盼望懂的朋友 来讲讲。
{
Exception deferredException = null;
bool flag;
if (row == null)
{
throw ExceptionBuilder.ArgumentNull("row");
}
if (row.Table != this)
{
throw ExceptionBuilder.RowAlreadyInOtherCollection();
}
if (row.rowID != -1)
{
throw ExceptionBuilder.RowAlreadyInTheCollection();
}
row.BeginEdit();
int tempRecord = row.tempRecord;
row.tempRecord = -1;
if (proposedID == -1)
{
proposedID = this.nextRowID;
}
if (flag = this.nextRowID <= proposedID)
{
this.nextRowID = proposedID + 1;
}
try
{
try
{
row.rowID = proposedID;
this.SetNewRecordWorker(row, tempRecord, DataRowAction.Add, false, pos, fireEvent, out deferredException);
}
catch
{
if (flag && (this.nextRowID == (proposedID + 1)))
{
this.nextRowID = proposedID;
}
row.rowID = -1;
row.tempRecord = tempRecord;
throw;
}
if (deferredException != null)
{
throw deferredException;
}
if (this.EnforceConstraints && !this.inLoad)
{
int count = this.columnCollection.Count;
for (int i = 0; i < count; i++)
{
DataColumn column = this.columnCollection[i];
if (column.Computed)
{
column.CheckColumnConstraint(row, DataRowAction.Add);
}
}
}
}
finally
{
row.ResetLastChangedColumn();
}
}上面是代码 盼望懂的朋友 来讲讲。
解决方案 »
- 为什么会在基类及其子类的定义中实现同一个接口
- 各位大神帮忙
- 紧急求助
- 求助 无直接联系窗口如何传值
- 如何:用c# ,将若干个Word中的某个cell的内容用paste的方法黏贴到另一个Word中的一个cell中,
- 急!!!在线等回复!!!关于C# WINFORM PANEL的问题
- How to bind muti-DataTable to one DataGrid(GridView)?
- 请问如何移植该语句到VB .Net中
- 如何区分是本地文件还是远程文件???
- C#如何取得第三方(C++)库返回的LPSTR?
- C# 中怎么设置节点不可用
- 有关C#派生类中隐藏基类虚函数的一点困惑(附:神奇的代码一段)
dt.Columns.Add("标题名"); DataRow row = dt.NewRow();
row[0] = "121"; dt.Rows.Add(row);
算了 分就给楼上的2位了。