本文整理汇总了C#中DataTable.AcceptChanges方法的典型用法代码示例。如果您正苦于以下问题:C# DataTable.AcceptChanges方法的具体用法?C# DataTable.AcceptChanges怎么用?C# DataTable.AcceptChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataTable
的用法示例。
在下文中一共展示了DataTable.AcceptChanges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load_RowStateUpsertUnpresent
public void Load_RowStateUpsertUnpresent()
{
localSetup();
_dt.Rows.Add(new object[] { 4, "mono 4" });
DataTable dtLoad = new DataTable("LoadRowStateChanges");
dtLoad.Columns.Add("id", typeof(int));
dtLoad.Columns.Add("name", typeof(string));
dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
dtLoad.Rows.Add(new object[] { 1, "RowState 1" });
dtLoad.Rows.Add(new object[] { 2, "RowState 2" });
dtLoad.Rows.Add(new object[] { 3, "RowState 3" });
dtLoad.AcceptChanges();
DataTableReader dtr = _dt.CreateDataReader();
dtLoad.Load(dtr, LoadOption.Upsert);
try
{
Assert.Equal(" ", dtLoad.Rows[3][1, DataRowVersion.Original]);
Assert.False(true);
}
catch (VersionNotFoundException)
{
}
}
示例2: Load_RowStateUpsertDuplicateKey2
public void Load_RowStateUpsertDuplicateKey2()
{
localSetup();
_dt.Rows.Add(new object[] { 4, "mono 4" });
DataTable dtLoad = new DataTable("LoadRowStateChanges");
dtLoad.Columns.Add("id", typeof(int));
dtLoad.Columns.Add("name", typeof(string));
dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
dtLoad.Rows.Add(new object[] { 1, "RowState 1" });
dtLoad.Rows.Add(new object[] { 2, "RowState 2" });
dtLoad.Rows.Add(new object[] { 3, "RowState 3" });
dtLoad.AcceptChanges();
dtLoad.Rows[2].Delete();
DataTableReader dtr = _dt.CreateDataReader();
dtLoad.Load(dtr, LoadOption.Upsert);
dtLoad.AcceptChanges();
try
{
Assert.Equal(" ", dtLoad.Rows[4][1]);
Assert.False(true);
}
catch (IndexOutOfRangeException)
{
}
}
示例3: DataViewTest
public DataViewTest()
{
_dataTable = new DataTable("itemTable");
_dc1 = new DataColumn("itemId");
_dc2 = new DataColumn("itemName");
_dc3 = new DataColumn("itemPrice");
_dc4 = new DataColumn("itemCategory");
_dataTable.Columns.Add(_dc1);
_dataTable.Columns.Add(_dc2);
_dataTable.Columns.Add(_dc3);
_dataTable.Columns.Add(_dc4);
DataRow dr;
_seed = 123;
_rowCount = 5;
_rndm = new Random(_seed);
for (int i = 1; i <= _rowCount; i++)
{
dr = _dataTable.NewRow();
dr["itemId"] = "item " + i;
dr["itemName"] = "name " + _rndm.Next();
dr["itemPrice"] = "Rs. " + (_rndm.Next() % 1000);
dr["itemCategory"] = "Cat " + ((_rndm.Next() % 10) + 1);
_dataTable.Rows.Add(dr);
}
_dataTable.AcceptChanges();
_dataView = new DataView(_dataTable);
_dataView.ListChanged += new ListChangedEventHandler(OnListChanged);
_listChangedArgs = null;
}
示例4: CreateChildDataTable
public static DataTable CreateChildDataTable()
{
DataTable dtChild = new DataTable("Child");
dtChild.Columns.Add("ParentId", typeof(int));
dtChild.Columns.Add("ChildId", typeof(int));
dtChild.Columns.Add("String1", typeof(string));
dtChild.Columns.Add("String2", typeof(string));
dtChild.Columns.Add("ChildDateTime", typeof(DateTime));
dtChild.Columns.Add("ChildDouble", typeof(double));
dtChild.Rows.Add(new object[] { 1, 1, "1-String1", "1-String2", new DateTime(2000, 1, 1, 0, 0, 0, 0), 1.534 });
dtChild.Rows.Add(new object[] { 1, 2, "2-String1", "2-String2", DateTime.MaxValue, -1.534 });
dtChild.Rows.Add(new object[] { 1, 3, "3-String1", "3-String2", DateTime.MinValue, double.MaxValue / 10000 });
dtChild.Rows.Add(new object[] { 2, 1, "1-String1", "1-String2", new DateTime(1973, 6, 20, 0, 0, 0, 0), double.MinValue * 10000 });
dtChild.Rows.Add(new object[] { 2, 2, "2-String1", "2-String2", new DateTime(2008, 12, 1, 13, 59, 59, 59), 0.45 });
dtChild.Rows.Add(new object[] { 2, 3, "3-String1", "3-String2", new DateTime(2003, 1, 1, 1, 1, 1, 1), 0.55 });
dtChild.Rows.Add(new object[] { 5, 1, "1-String1", "1-String2", new DateTime(2002, 1, 1, 1, 1, 1, 1), 0 });
dtChild.Rows.Add(new object[] { 5, 2, "2-String1", "2-String2", new DateTime(2001, 1, 1, 1, 1, 1, 1), 10 });
dtChild.Rows.Add(new object[] { 5, 3, "3-String1", "3-String2", new DateTime(2000, 1, 1, 1, 1, 1, 1), 20 });
dtChild.Rows.Add(new object[] { 6, 1, "1-String1", "1-String2", new DateTime(2000, 1, 1, 1, 1, 1, 0), 25 });
dtChild.Rows.Add(new object[] { 6, 2, "2-String1", "2-String2", new DateTime(2000, 1, 1, 1, 1, 0, 0), 30 });
dtChild.Rows.Add(new object[] { 6, 3, "3-String1", "3-String2", new DateTime(2000, 1, 1, 0, 0, 0, 0), 35 });
dtChild.AcceptChanges();
return dtChild;
}
示例5: AcceptChanges
public void AcceptChanges()
{
DataTable myTable = new DataTable("myTable");
DataRow myRow;
myRow = myTable.NewRow();
myTable.Rows.Add(myRow);
// DataRow AcceptChanges
// DataRowState.Added -> DataRowState.Unchanged
myTable.AcceptChanges();
Assert.Equal(DataRowState.Unchanged, myRow.RowState);
}
示例6: DataTableReaderTest
public DataTableReaderTest()
{
_dt = new DataTable("test");
_dt.Columns.Add("id", typeof(int));
_dt.Columns.Add("name", typeof(string));
_dt.PrimaryKey = new DataColumn[] { _dt.Columns["id"] };
_dt.Rows.Add(new object[] { 1, "mono 1" });
_dt.Rows.Add(new object[] { 2, "mono 2" });
_dt.Rows.Add(new object[] { 3, "mono 3" });
_dt.AcceptChanges();
}
示例7: LoadRowTest
public void LoadRowTest()
{
DataTable dt = new DataTable();
dt.Columns.Add("id", typeof(int));
dt.Columns.Add("name", typeof(string));
dt.Rows.Add(new object[] { 1, "mono 1" });
dt.Rows.Add(new object[] { 2, "mono 2" });
dt.Rows.Add(new object[] { 3, "mono 3" });
dt.PrimaryKey = new DataColumn[] { dt.Columns["id"] };
dt.AcceptChanges();
dt.LoadDataRow(new object[] { 4, "mono 4" }, LoadOption.Upsert);
Assert.Equal(4, dt.Rows.Count);
}
示例8: CreateParentDataTable
public static DataTable CreateParentDataTable()
{
DataTable dtParent = new DataTable("Parent");
dtParent.Columns.Add("ParentId", typeof(int));
dtParent.Columns.Add("String1", typeof(string));
dtParent.Columns.Add("String2", typeof(string));
dtParent.Columns.Add("ParentDateTime", typeof(DateTime));
dtParent.Columns.Add("ParentDouble", typeof(double));
dtParent.Columns.Add("ParentBool", typeof(bool));
dtParent.Rows.Add(new object[] { 1, "1-String1", "1-String2", new DateTime(2005, 1, 1, 0, 0, 0, 0), 1.534, true });
dtParent.Rows.Add(new object[] { 2, "2-String1", "2-String2", new DateTime(2004, 1, 1, 0, 0, 0, 1), -1.534, true });
dtParent.Rows.Add(new object[] { 3, "3-String1", "3-String2", new DateTime(2003, 1, 1, 0, 0, 1, 0), double.MinValue * 10000, false });
dtParent.Rows.Add(new object[] { 4, "4-String1", "4-String2", new DateTime(2002, 1, 1, 0, 1, 0, 0), double.MaxValue / 10000, true });
dtParent.Rows.Add(new object[] { 5, "5-String1", "5-String2", new DateTime(2001, 1, 1, 1, 0, 0, 0), 0.755, true });
dtParent.Rows.Add(new object[] { 6, "6-String1", "6-String2", new DateTime(2000, 1, 1, 0, 0, 0, 0), 0.001, false });
dtParent.AcceptChanges();
return dtParent;
}
示例9: ToTableTest_DataValidity
public void ToTableTest_DataValidity()
{
DataTable table = new DataTable();
table.Columns.Add("col1", typeof(int));
table.Columns.Add("col2", typeof(int));
table.Columns.Add("col3", typeof(int));
for (int i = 0; i < 5; ++i)
{
table.Rows.Add(new object[] { i, i + 1, i + 2 });
table.Rows.Add(new object[] { i, i + 1, i + 2 });
}
table.AcceptChanges();
DataView view = new DataView(table);
try
{
DataTable newTable = view.ToTable(false, null);
}
catch (ArgumentNullException e)
{
// Never premise English.
//Assert.Equal ("'columnNames' argument cannot be null." + Environment.NewLine +
// "Parameter name: columnNames", e.Message, "#1");
}
DataTable newTable1 = view.ToTable(false, new string[] { });
Assert.Equal(10, newTable1.Rows.Count);
newTable1 = view.ToTable(true, new string[] { });
Assert.Equal(3, newTable1.Columns.Count);
Assert.Equal(5, newTable1.Rows.Count);
table.Rows.Add(new object[] { 1, 100, 100 });
newTable1 = view.ToTable(true, new string[] { });
Assert.Equal(3, newTable1.Columns.Count);
Assert.Equal(6, newTable1.Rows.Count);
newTable1 = view.ToTable(true, new string[] { "col1" });
Assert.Equal(1, newTable1.Columns.Count);
Assert.Equal(5, newTable1.Rows.Count);
newTable1 = view.ToTable(true, new string[] { "col2", "col3" });
Assert.Equal(2, newTable1.Columns.Count);
Assert.Equal(6, newTable1.Rows.Count);
for (int i = 0; i < newTable1.Rows.Count; ++i)
Assert.Equal(DataRowState.Added, newTable1.Rows[i].RowState);
view = new DataView(table, "col1>1", "col1 asc, col2 desc", DataViewRowState.Added);
Assert.Equal(0, view.Count);
newTable1 = view.ToTable(false, new string[] { "col1", "col3" });
Assert.Equal(0, newTable1.Rows.Count);
table.Rows.Add(new object[] { 10, 1, 1 });
table.Rows.Add(new object[] { 10, 1, 3 });
table.Rows.Add(new object[] { 10, 1, 2 });
Assert.Equal(3, view.Count);
view.Sort = "col1 asc, col2 asc, col3 desc";
newTable1 = view.ToTable(true, new string[] { "col1", "col3" });
Assert.Equal(3, newTable1.Rows.Count);
Assert.Equal(3, newTable1.Rows[0][1]);
Assert.Equal(2, newTable1.Rows[1][1]);
Assert.Equal(1, newTable1.Rows[2][1]);
}
示例10: ListChangeOnSetItem
public void ListChangeOnSetItem()
{
DataTable dt = new DataTable("table");
dt.Columns.Add("col1");
dt.Columns.Add("col2");
dt.Columns.Add("col3");
dt.Rows.Add(new object[] { 1, 2, 3 });
dt.AcceptChanges();
DataView dv = new DataView(dt);
dv.ListChanged += new ListChangedEventHandler(OnChange);
dv[0]["col1"] = 4;
}
示例11: Load_RowStateChangesDefaultDelete
public void Load_RowStateChangesDefaultDelete()
{
localSetup();
DataTable dtLoad = new DataTable("LoadRowStateChanges");
dtLoad.Columns.Add("id", typeof(int));
dtLoad.Columns.Add("name", typeof(string));
dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
dtLoad.Rows.Add(new object[] { 1, "RowState 1" });
dtLoad.Rows.Add(new object[] { 2, "RowState 2" });
dtLoad.Rows.Add(new object[] { 3, "RowState 3" });
dtLoad.AcceptChanges();
dtLoad.Rows[2].Delete();
DataTableReader dtr = _dt.CreateDataReader();
dtLoad.Load(dtr);
try
{
Assert.Equal(" ", dtLoad.Rows[2][1, DataRowVersion.Current]);
Assert.False(true);
}
catch (VersionNotFoundException)
{
}
}
示例12: Load_RowStateUpsertUnchangedEqualVal
public void Load_RowStateUpsertUnchangedEqualVal()
{
localSetup();
DataTable dtLoad = new DataTable("LoadRowStateChanges");
dtLoad.Columns.Add("id", typeof(int));
dtLoad.Columns.Add("name", typeof(string));
dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
dtLoad.Rows.Add(new object[] { 1, "mono 1" });
dtLoad.AcceptChanges();
DataTableReader dtr = _dt.CreateDataReader();
DataRowAction[] dra = new DataRowAction[] {
DataRowAction.Nothing,// REAL action
DataRowAction.Nothing,// dummy
DataRowAction.Nothing,// dummy
DataRowAction.Nothing,// dummy
DataRowAction.Nothing};// dummy
rowActionInit(dra);
dtLoad.Load(dtr, LoadOption.Upsert);
rowActionEnd();
Assert.Equal("mono 1", dtLoad.Rows[0][1, DataRowVersion.Current]);
Assert.Equal("mono 1", dtLoad.Rows[0][1, DataRowVersion.Original]);
Assert.Equal(DataRowState.Unchanged, dtLoad.Rows[0].RowState);
}
示例13: MultipleResultSetsTest
public void MultipleResultSetsTest()
{
DataTable dt1 = new DataTable("test2");
dt1.Columns.Add("x", typeof(string));
dt1.Rows.Add(new object[] { "test" });
dt1.Rows.Add(new object[] { "test1" });
dt1.AcceptChanges();
DataTable[] collection = new DataTable[] { _dt, dt1 };
DataTableReader reader = new DataTableReader(collection);
try
{
int i = 0;
do
{
while (reader.Read())
i++;
} while (reader.NextResult());
Assert.Equal(5, i);
}
finally
{
if (reader != null && !reader.IsClosed)
reader.Close();
}
}
示例14: MakeDummyTable
private void MakeDummyTable()
{
// Create a new Table
_dataSet = new DataSet();
_dummyTable = new DataTable("DummyTable");
DataColumn column;
DataRow row;
// Create new DataColumn, set DataType,
// ColumnName and add to Table.
column = new DataColumn();
column.DataType = typeof(int);
column.ColumnName = "id";
column.Unique = true;
// Add the Column to the DataColumnCollection.
_dummyTable.Columns.Add(column);
// Create second column
column = new DataColumn();
column.DataType = typeof(string);
column.ColumnName = "DummyItem";
column.AutoIncrement = false;
column.Caption = "DummyItem";
column.Unique = false;
// Add the column to the table
_dummyTable.Columns.Add(column);
_dataSet.Tables.Add(_dummyTable);
// Create three new DataRow objects and add
// them to the DataTable
for (int i = 0; i <= 2; i++)
{
row = _dummyTable.NewRow();
row["id"] = i + 1;
row["DummyItem"] = "DummyItem " + (i + 1);
_dummyTable.Rows.Add(row);
}
DataRow row1 = _dummyTable.Rows[1];
_dummyTable.AcceptChanges();
row1.BeginEdit();
row1[1] = "Changed_DummyItem " + 2;
row1.EndEdit();
}
示例15: setModified_testRollback
public void setModified_testRollback()
{
DataTable table = new DataTable();
table.Columns.Add("col1", typeof(int));
table.Columns.Add("col2", typeof(int));
DataRow row = table.Rows.Add(new object[] { 1, 1 });
table.AcceptChanges();
row.SetModified();
Assert.Equal(row.RowState, DataRowState.Modified);
Assert.Equal(1, row[0, DataRowVersion.Current]);
Assert.Equal(1, row[0, DataRowVersion.Original]);
table.RejectChanges();
Assert.Equal(row.RowState, DataRowState.Unchanged);
}