本文整理汇总了C#中DataView.FindRows方法的典型用法代码示例。如果您正苦于以下问题:C# DataView.FindRows方法的具体用法?C# DataView.FindRows怎么用?C# DataView.FindRows使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataView
的用法示例。
在下文中一共展示了DataView.FindRows方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindRows_ByKeys
public void FindRows_ByKeys()
{
DataRowView[] dvArr = null;
//create the source datatable
DataTable dt = DataProvider.CreateChildDataTable();
//create the dataview for the table
DataView dv = new DataView(dt);
// FindRows ,no sort - exception
Assert.Throws<ArgumentException>(() =>
{
dvArr = dv.FindRows(new object[] { "3", "3-String1" });
});
dv.Sort = "String1,ChildId";
// Find = wrong sort, can not find
Assert.Throws<FormatException>(() =>
{
dvArr = dv.FindRows(new object[] { "3", "3-String1" });
});
dv.Sort = "ChildId,String1";
//get expected results
DataRow[] drExpected = dt.Select("ChildId=3 and String1='3-String1'");
// FindRows - check count
dvArr = dv.FindRows(new object[] { "3", "3-String1" });
Assert.Equal(drExpected.Length, dvArr.Length);
// FindRows - check data
//check that result is ok
bool Succeed = true;
for (int i = 0; i < dvArr.Length; i++)
{
Succeed = (int)dvArr[i]["ChildId"] == (int)drExpected[i]["ChildId"];
if (!Succeed) break;
}
Assert.Equal(true, Succeed);
}
示例2: TestFindRows
public void TestFindRows()
{
DataView TestView = new DataView(_dataTable);
TestView.Sort = "itemId";
DataRowView[] Result = TestView.FindRows("item 3");
Assert.Equal(1, Result.Length);
Assert.Equal("item 3", Result[0]["itemId"]);
}
示例3: FindRowsInconsistentKeyLength
public void FindRowsInconsistentKeyLength()
{
Assert.Throws<ArgumentException>(() =>
{
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.Rows.Add(new object[] { 4, 5, 6 });
dt.Rows.Add(new object[] { 4, 7, 8 });
dt.Rows.Add(new object[] { 5, 7, 8 });
dt.Rows.Add(new object[] { 4, 8, 9 });
DataView dv = new DataView(dt, null, "col1",
DataViewRowState.CurrentRows);
dv.FindRows(new object[] { 1, 2, 3 });
});
}