本文整理汇总了C#中DataTable.GetErrors方法的典型用法代码示例。如果您正苦于以下问题:C# DataTable.GetErrors方法的具体用法?C# DataTable.GetErrors怎么用?C# DataTable.GetErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataTable
的用法示例。
在下文中一共展示了DataTable.GetErrors方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestRowErrors
public void TestRowErrors()
{
DataTable table = new DataTable();
DataColumn col1 = table.Columns.Add("col1", typeof(int));
DataColumn col2 = table.Columns.Add("col2", typeof(int));
DataColumn col3 = table.Columns.Add("col3", typeof(int));
col1.AllowDBNull = false;
table.Constraints.Add("uc", new DataColumn[] { col2, col3 }, false);
table.BeginLoadData();
table.Rows.Add(new object[] { null, 1, 1 });
table.Rows.Add(new object[] { 1, 1, 1 });
try
{
table.EndLoadData();
Assert.False(true);
}
catch (ConstraintException) { }
Assert.True(table.HasErrors);
DataRow[] rows = table.GetErrors();
Assert.Equal(2, rows.Length);
Assert.Equal("Column 'col1' does not allow DBNull.Value.", table.Rows[0].RowError);
Assert.Equal("Column 'col2, col3' is constrained to be unique. Value '1, 1' is already present."
, table.Rows[1].RowError);
Assert.Equal(table.Rows[0].RowError, table.Rows[0].GetColumnError(0));
Assert.Equal(table.Rows[1].RowError, table.Rows[0].GetColumnError(1));
Assert.Equal(table.Rows[1].RowError, table.Rows[0].GetColumnError(2));
Assert.Equal("", table.Rows[1].GetColumnError(0));
Assert.Equal(table.Rows[1].RowError, table.Rows[1].GetColumnError(1));
Assert.Equal(table.Rows[1].RowError, table.Rows[1].GetColumnError(2));
}
示例2: GetErrors
public void GetErrors()
{
DataTable table = new DataTable();
DataColumn col = new DataColumn();
col.ColumnName = "Id";
col.DataType = typeof(int);
table.Columns.Add(col);
col = new DataColumn();
col.ColumnName = "Name";
col.DataType = typeof(string);
table.Columns.Add(col);
DataRow row = table.NewRow();
row["Id"] = 147;
row["name"] = "Abc";
row.RowError = "Error#1";
table.Rows.Add(row);
Assert.Equal(1, table.GetErrors().Length);
Assert.Equal("Error#1", (table.GetErrors())[0].RowError);
}