本文整理汇总了C#中System.Data.DataView.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# DataView.CopyTo方法的具体用法?C# DataView.CopyTo怎么用?C# DataView.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.DataView
的用法示例。
在下文中一共展示了DataView.CopyTo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RowFilter
[Test] public void RowFilter()
{
//note: this test does not check all the possible row filter expression. this is done in DataTable.Select method.
// this test also check DataView.Count property
DataRowView[] drvResult = null;
ArrayList al = new ArrayList();
//create the source datatable
DataTable dt = DataProvider.CreateChildDataTable();
//create the dataview for the table
DataView dv = new DataView(dt);
//-------------------------------------------------------------
//Get excpected result
al.Clear();
foreach (DataRow dr in dt.Rows )
{
if ((int)dr["ChildId"] == 1)
{
al.Add(dr);
}
}
// RowFilter = 'ChildId=1', check count
dv.RowFilter = "ChildId=1";
Assert.AreEqual(al.Count , dv.Count , "DV70");
// RowFilter = 'ChildId=1', check rows
drvResult = new DataRowView[dv.Count];
dv.CopyTo(drvResult,0);
//check that the filterd rows exists
bool Succeed = true;
for (int i=0; i<drvResult.Length ; i++)
{
Succeed = al.Contains(drvResult[i].Row);
if (!Succeed) break;
}
Assert.AreEqual(true, Succeed , "DV71");
//-------------------------------------------------------------
//-------------------------------------------------------------
//Get excpected result
al.Clear();
foreach (DataRow dr in dt.Rows )
if ((int)dr["ChildId"] == 1 && dr["String1"].ToString() == "1-String1" )
al.Add(dr);
// RowFilter - ChildId=1 and String1='1-String1'
dv.RowFilter = "ChildId=1 and String1='1-String1'";
Assert.AreEqual(al.Count , dv.Count , "DV72");
// RowFilter = ChildId=1 and String1='1-String1', check rows
drvResult = new DataRowView[dv.Count];
dv.CopyTo(drvResult,0);
//check that the filterd rows exists
Succeed = true;
for (int i=0; i<drvResult.Length ; i++)
{
Succeed = al.Contains(drvResult[i].Row);
if (!Succeed) break;
}
Assert.AreEqual(true, Succeed , "DV73");
//-------------------------------------------------------------
//EvaluateException
// RowFilter - check EvaluateException
try
{
dv.RowFilter = "Col=1";
Assert.Fail("DV74: RowFilter Failed to throw EvaluateException");
}
catch (EvaluateException) {}
catch (AssertionException exc) {throw exc;}
catch (Exception exc)
{
Assert.Fail("DV75: RowFilter. Wrong exception type. Got:" + exc);
}
//SyntaxErrorException 1
// RowFilter - check SyntaxErrorException 1
try
{
dv.RowFilter = "sum('something')";
Assert.Fail("DV76: RowFilter Failed to throw SyntaxErrorException");
}
catch (SyntaxErrorException) {}
catch (AssertionException exc) {throw exc;}
catch (Exception exc)
{
Assert.Fail("DV77: RowFilter. Wrong exception type. Got:" + exc);
}
//SyntaxErrorException 2
// RowFilter - check SyntaxErrorException 2
try
{
dv.RowFilter = "HH**!";
Assert.Fail("DV78: RowFilter Failed to throw SyntaxErrorException");
//.........这里部分代码省略.........
示例2: run
//Activate This Construntor to log All To Standard output
//public TestClass():base(true){}
//Activate this constructor to log Failures to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, false){}
//Activate this constructor to log All to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, true){}
//BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
public void run()
{
Exception exp = null;
//create the source datatable
DataTable dt = GHTUtils.DataProvider.CreateChildDataTable();
//create the dataview for the table
DataView dv = new DataView(dt);
DataRowView[] drvExpected = null;
DataRowView[] drvResult = null;
// ------- Copy from Index=0
drvExpected = new DataRowView[dv.Count];
for (int i=0; i < dv.Count ;i++)
{
drvExpected[i] = dv[i];
}
drvResult = new DataRowView[dv.Count];
try
{
BeginCase("CopyTo from index 0");
dv.CopyTo(drvResult,0);
Compare(drvExpected ,drvResult);
}
catch(Exception ex)
{
exp = ex;
}
finally
{
EndCase(exp);
exp = null;
}
// ------- Copy from Index=3
drvExpected = new DataRowView[dv.Count+3];
for (int i=0; i < dv.Count ;i++)
{
drvExpected[i+3] = dv[i];
}
drvResult = new DataRowView[dv.Count+3];
try
{
BeginCase("CopyTo from index 3");
dv.CopyTo(drvResult,3);
Compare(drvExpected ,drvResult );
}
catch(Exception ex)
{
exp = ex;
}
finally
{
EndCase(exp);
exp = null;
}
// ------- Copy from Index=3,larger array
drvExpected = new DataRowView[dv.Count+9];
for (int i=0; i < dv.Count ;i++)
{
drvExpected[i+3] = dv[i];
}
drvResult = new DataRowView[dv.Count+9];
try
{
BeginCase("CopyTo from index 3,larger array");
dv.CopyTo(drvResult,3);
Compare(drvExpected ,drvResult);
}
catch(Exception ex)
{
exp = ex;
}
finally
{
EndCase(exp);
exp = null;
}
// ------- CopyTo smaller array, check exception
drvResult = new DataRowView[dv.Count-1];
//.........这里部分代码省略.........
示例3: CopyTo
[Test] public void CopyTo()
{
//create the source datatable
DataTable dt = DataProvider.CreateChildDataTable();
//create the dataview for the table
DataView dv = new DataView(dt);
DataRowView[] drvExpected = null;
DataRowView[] drvResult = null;
// ------- Copy from Index=0
drvExpected = new DataRowView[dv.Count];
for (int i=0; i < dv.Count ;i++)
{
drvExpected[i] = dv[i];
}
drvResult = new DataRowView[dv.Count];
// CopyTo from index 0
dv.CopyTo(drvResult,0);
Assert.AreEqual(drvResult, drvExpected , "DV27");
// ------- Copy from Index=3
drvExpected = new DataRowView[dv.Count+3];
for (int i=0; i < dv.Count ;i++)
{
drvExpected[i+3] = dv[i];
}
drvResult = new DataRowView[dv.Count+3];
// CopyTo from index 3
dv.CopyTo(drvResult,3);
Assert.AreEqual(drvResult , drvExpected , "DV28");
// ------- Copy from Index=3,larger array
drvExpected = new DataRowView[dv.Count+9];
for (int i=0; i < dv.Count ;i++)
{
drvExpected[i+3] = dv[i];
}
drvResult = new DataRowView[dv.Count+9];
// CopyTo from index 3,larger array
dv.CopyTo(drvResult,3);
Assert.AreEqual(drvResult, drvExpected , "DV29");
// ------- CopyTo smaller array, check exception
drvResult = new DataRowView[dv.Count-1];
// CopyTo smaller array, check exception
try
{
dv.CopyTo(drvResult,0);
Assert.Fail("DV30: CopyTo Failed to throw IndexOutOfRangeException");
}
catch (IndexOutOfRangeException) {}
catch (AssertionException exc) {throw exc;}
catch (Exception exc)
{
Assert.Fail("DV31: CopyTo. Wrong exception type. Got:" + exc);
}
}
示例4: run
//Activate This Construntor to log All To Standard output
//public TestClass():base(true){}
//Activate this constructor to log Failures to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, false){}
//Activate this constructor to log All to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, true){}
//BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
public void run()
{
//note: this test does not check all the possible row filter expression. this is done in DataTable.Select method.
// this test also check DataView.Count property
Exception exp = null;
DataRowView[] drvResult = null;
System.Collections.ArrayList al = new System.Collections.ArrayList();
//create the source datatable
DataTable dt = GHTUtils.DataProvider.CreateChildDataTable();
//create the dataview for the table
DataView dv = new DataView(dt);
//-------------------------------------------------------------
//Get excpected result
al.Clear();
foreach (DataRow dr in dt.Rows )
{
if ((int)dr["ChildId"] == 1)
{
al.Add(dr);
}
}
try
{
BeginCase("RowFilter = 'ChildId=1', check count");
dv.RowFilter = "ChildId=1";
Compare(dv.Count ,al.Count );
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
try
{
BeginCase("RowFilter = 'ChildId=1', check rows");
drvResult = new DataRowView[dv.Count];
dv.CopyTo(drvResult,0);
//check that the filterd rows exists
bool Succeed = true;
for (int i=0; i<drvResult.Length ; i++)
{
Succeed = al.Contains(drvResult[i].Row);
if (!Succeed) break;
}
Compare(Succeed ,true);
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
//-------------------------------------------------------------
//-------------------------------------------------------------
//Get excpected result
al.Clear();
foreach (DataRow dr in dt.Rows )
if ((int)dr["ChildId"] == 1 && dr["String1"].ToString() == "1-String1" )
al.Add(dr);
try
{
BeginCase("RowFilter - ChildId=1 and String1='1-String1'");
dv.RowFilter = "ChildId=1 and String1='1-String1'";
Compare(dv.Count ,al.Count );
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
try
{
BeginCase("RowFilter = ChildId=1 and String1='1-String1', check rows");
drvResult = new DataRowView[dv.Count];
dv.CopyTo(drvResult,0);
//check that the filterd rows exists
bool Succeed = true;
for (int i=0; i<drvResult.Length ; i++)
{
Succeed = al.Contains(drvResult[i].Row);
if (!Succeed) break;
}
Compare(Succeed ,true);
}
catch(Exception ex) {exp = ex;}
//.........这里部分代码省略.........