本文整理汇总了C#中DataView.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# DataView.Delete方法的具体用法?C# DataView.Delete怎么用?C# DataView.Delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataView
的用法示例。
在下文中一共展示了DataView.Delete方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AllowDelete
public void AllowDelete()
{
DataTable dt = DataProvider.CreateParentDataTable();
DataView dv = new DataView(dt);
// AllowDelete - default value
Assert.Equal(true, dv.AllowDelete);
// AllowDelete - true
dv.AllowDelete = true;
Assert.Equal(true, dv.AllowDelete);
// AllowDelete - false
dv.AllowDelete = false;
Assert.Equal(false, dv.AllowDelete);
dv.AllowDelete = false;
// AllowDelete false- Exception
Assert.Throws<DataException>(() =>
{
dv.Delete(0);
});
dv.AllowDelete = true;
int RowsCount = dv.Count;
// AllowDelete true- Exception
dv.Delete(0);
Assert.Equal(RowsCount - 1, dv.Count);
}
示例2: TestDeleteAndCount
public void TestDeleteAndCount()
{
DataSet dataset = new DataSet("new");
DataTable dt = new DataTable("table1");
dataset.Tables.Add(dt);
dt.Columns.Add("col1");
dt.Columns.Add("col2");
dt.Rows.Add(new object[] { 1, 1 });
dt.Rows.Add(new object[] { 1, 2 });
dt.Rows.Add(new object[] { 1, 3 });
DataView dataView = new DataView(dataset.Tables[0]);
Assert.Equal(3, dataView.Count);
dataView.AllowDelete = true;
// Deleting the first row
dataView.Delete(0);
Assert.Equal(2, dataView.Count);
}
示例3: Delete
public void Delete()
{
//create the source datatable
DataTable dt = DataProvider.CreateChildDataTable();
//create the dataview for the table
DataView dv = new DataView(dt);
int CountView = dv.Count;
int CountTable = dt.Rows.Count;
DataRowView drv = dv[0];
// Delete - DataView Row Count
dv.Delete(0);
Assert.Equal(dv.Count, CountView - 1);
// Delete - Table Row Count
Assert.Equal(dt.Rows.Count, CountTable);
// Delete - check table
Assert.Equal(dt, drv.Row.Table);
}
示例4: TestDeleteClosed
public void TestDeleteClosed()
{
Assert.Throws<IndexOutOfRangeException>(() =>
{
DataView TestView = new DataView(_dataTable);
TestView.Dispose(); // Close the table
TestView.Delete(0); // cannot access to item at 0.
});
}
示例5: TestDeleteNotAllowed
public void TestDeleteNotAllowed()
{
Assert.Throws<DataException>(() =>
{
DataView TestView = new DataView(_dataTable);
TestView.AllowDelete = false;
TestView.Delete(0);
});
}
示例6: TestDeleteOutOfBounds
public void TestDeleteOutOfBounds()
{
Assert.Throws<IndexOutOfRangeException>(() =>
{
DataView TestView = new DataView(_dataTable);
TestView.Delete(100);
});
}
示例7: TestDelete
public void TestDelete()
{
Assert.Throws<DeletedRowInaccessibleException>(() =>
{
DataView TestView = new DataView(_dataTable);
TestView.Delete(0);
DataRow r = TestView.Table.Rows[0];
Assert.True(!((string)r["itemId"] == "item 1"));
});
}
示例8: RowStateFilter_2
public void RowStateFilter_2()
{
DataSet dataset = new DataSet("new");
DataTable dt = new DataTable("table1");
dataset.Tables.Add(dt);
dt.Columns.Add("col1");
dt.Columns.Add("col2");
dt.Rows.Add(new object[] { 1, 1 });
dt.Rows.Add(new object[] { 1, 2 });
dt.Rows.Add(new object[] { 1, 3 });
dataset.AcceptChanges();
DataView dataView = new DataView(dataset.Tables[0]);
// 'new' table in this sample contains 6 records
dataView.AllowEdit = true;
dataView.AllowDelete = true;
string v;
// Editing the row
dataView[0]["col1"] = -1;
dataView.RowStateFilter = DataViewRowState.ModifiedOriginal;
v = dataView[0][0].ToString();
Assert.Equal(1, dataView.Count);
Assert.Equal("1", v);
// Deleting the row
dataView.Delete(0);
dataView.RowStateFilter = DataViewRowState.Deleted;
v = dataView[0][0].ToString();
Assert.Equal(1, dataView.Count);
Assert.Equal("1", v);
}