DataRow.SetColumnError 方法

定义

为列设置错误说明。Sets the error description for a column.

重载

SetColumnError(DataColumn, String)

为指定为 DataColumn 的列设置错误说明。Sets the error description for a column specified as a DataColumn.

SetColumnError(Int32, String)

为由索引指定的列设置错误说明。Sets the error description for a column specified by index.

SetColumnError(String, String)

为由名称指定的列设置错误说明。Sets the error description for a column specified by name.

SetColumnError(DataColumn, String)

为指定为 DataColumn 的列设置错误说明。Sets the error description for a column specified as a DataColumn.

public:
 void SetColumnError(System::Data::DataColumn ^ column, System::String ^ error);
public void SetColumnError (System.Data.DataColumn column, string? error);
public void SetColumnError (System.Data.DataColumn column, string error);
member this.SetColumnError : System.Data.DataColumn * string -> unit
Public Sub SetColumnError (column As DataColumn, error As String)

参数

column
DataColumn

为其设置错误说明的 DataColumnThe DataColumn to set the error description for.

error
String

错误说明。The error description.

示例

下面的示例为指定的设置了错误说明 DataRowThe following example sets an error description for a specified DataRow.

private void SetColError(DataRow row, int columnIndex)
{
    string errorString = "Replace this text.";

    // Set the error for the specified column of the row.
    row.SetColumnError(columnIndex, errorString);
}

private void PrintColError(DataRow row, int columnIndex)
{
    // Print the error of a specified column.
    Console.WriteLine(row.GetColumnError(columnIndex));
}
Private Sub SetColError(ByVal row As DataRow, _
    byVal columnIndex As Integer)
    Dim errorString As String = "Replace this text."

    ' Set the error for the specified column of the row.
    row.SetColumnError(columnIndex, errorString)
End Sub
 
Private Sub PrintColError( _
    ByVal row As DataRow, byVal columnIndex As Integer)

    ' Print the error of a specified column.
    Console.WriteLine(row.GetColumnError(columnIndex))
End Sub

注解

若要检查错误说明,请使用 GetColumnError 方法。To examine error descriptions, use the GetColumnError method.

若要确定列集合是否存在任何错误,请使用 HasErrors 属性。To determine whether any errors exist for the columns collection, use the HasErrors property. 因此,您可以使用 GetColumnsInError 方法来检索所有包含错误的列。Consequently, you can use the GetColumnsInError method to retrieve all the columns with errors.

如果将 null 或空字符串作为 error 参数传入,则的 DataRow 行为就像未设置错误,并且 HasErrors 属性将返回 false。If null or an empty string is passed in as the error parameter, the DataRow behaves as if no error was set and the HasErrors property will return false.

若要对整行设置自定义错误说明,请使用 RowError 属性。To set a custom error description on the whole row, use the RowError property.

若要确定列集合是否存在任何错误,请使用 HasErrors 方法。To determine whether any errors exist for the columns collection, use the HasErrors method.

若要清除列集合的所有错误,请使用 ClearErrors 方法。To clear all errors for the columns collection, use the ClearErrors method.

另请参阅

适用于

SetColumnError(Int32, String)

为由索引指定的列设置错误说明。Sets the error description for a column specified by index.

public:
 void SetColumnError(int columnIndex, System::String ^ error);
public void SetColumnError (int columnIndex, string? error);
public void SetColumnError (int columnIndex, string error);
member this.SetColumnError : int * string -> unit
Public Sub SetColumnError (columnIndex As Integer, error As String)

参数

columnIndex
Int32

列的从零开始的索引。The zero-based index of the column.

error
String

错误说明。The error description.

例外

columnIndex 参数超出范围The columnIndex argument is out of range

示例

下面的示例为指定的设置了错误说明 DataRowThe following example sets an error description for a specified DataRow.

private void SetColError(DataRow row, int columnIndex)
{
    string errorString = "Replace this text.";

    // Set the error for the specified column of the row.
    row.SetColumnError(columnIndex, errorString);
}

private void PrintColError(DataRow row, int columnIndex)
{
    // Print the error of a specified column.
    Console.WriteLine(row.GetColumnError(columnIndex));
}
Private Sub SetColError(ByVal row As DataRow, _
    byVal columnIndex As Integer)
    Dim errorString As String = "Replace this text."

    ' Set the error for the specified column of the row.
    row.SetColumnError(columnIndex, errorString)
End Sub
 
Private Sub PrintColError( _
    ByVal row As DataRow, byVal columnIndex As Integer)

    ' Print the error of a specified column.
    Console.WriteLine(row.GetColumnError(columnIndex))
End Sub

注解

方法用于设置指定列上的自定义错误说明。The method is used to set custom error descriptions on specified columns. 可以使用 ErrorProvider 控件显示错误的文本。You can use the ErrorProvider control to display the text of the error.

若要检查错误说明,请使用 GetColumnError 方法。To examine error descriptions, use the GetColumnError method.

若要确定列集合是否存在任何错误,请使用 HasErrors 属性。To determine whether any errors exist for the columns collection, use the HasErrors property. 因此,您可以使用 GetColumnsInError 方法来检索所有包含错误的列。Consequently, you can use the GetColumnsInError method to retrieve all the columns with errors.

如果将 null 或空字符串作为 error 参数传入,则的 DataRow 行为就像未设置错误,并且 HasErrors 属性将返回 false。If null or an empty string is passed in as the error parameter, the DataRow behaves as if no error was set and the HasErrors property will return false.

若要对整行设置自定义错误说明,请使用 RowError 属性。To set a custom error description on the whole row, use the RowError property.

若要清除列集合的所有错误,请使用 ClearErrors 方法。To clear all errors for the columns collection, use the ClearErrors method.

若要设置适用于整行的错误文本,请设置 RowError 属性。To set error text that applies to a whole row, set the RowError property.

另请参阅

适用于

SetColumnError(String, String)

为由名称指定的列设置错误说明。Sets the error description for a column specified by name.

public:
 void SetColumnError(System::String ^ columnName, System::String ^ error);
public void SetColumnError (string columnName, string? error);
public void SetColumnError (string columnName, string error);
member this.SetColumnError : string * string -> unit
Public Sub SetColumnError (columnName As String, error As String)

参数

columnName
String

列的名称。The name of the column.

error
String

错误说明。The error description.

示例

下面的示例为指定的设置了错误说明 DataRowThe following example sets an error description for a specified DataRow.

private void SetColError(DataRow row, int columnIndex)
{
    string errorString = "Replace this text.";

    // Set the error for the specified column of the row.
    row.SetColumnError(columnIndex, errorString);
}

private void PrintColError(DataRow row, int columnIndex)
{
    // Print the error of a specified column.
    Console.WriteLine(row.GetColumnError(columnIndex));
}
Private Sub SetColError(ByVal row As DataRow, _
    byVal columnIndex As Integer)
    Dim errorString As String = "Replace this text."

    ' Set the error for the specified column of the row.
    row.SetColumnError(columnIndex, errorString)
End Sub
 
Private Sub PrintColError( _
    ByVal row As DataRow, byVal columnIndex As Integer)

    ' Print the error of a specified column.
    Console.WriteLine(row.GetColumnError(columnIndex))
End Sub

注解

使用类的属性设置列的名称 ColumnName DataColumnThe name of a column is set with the ColumnName property of the DataColumn class.

若要检查错误说明,请使用 GetColumnError 方法。To examine error descriptions, use the GetColumnError method.

若要确定列集合是否存在任何错误,请使用 HasErrors 属性。To determine whether any errors exist for the columns collection, use the HasErrors property. 因此,您可以使用 GetColumnsInError 方法来检索所有包含错误的列。Consequently, you can use the GetColumnsInError method to retrieve all the columns with errors.

如果将 null 或空字符串作为 error 参数传入,则的 DataRow 行为就像未设置错误,并且 HasErrors 属性将返回 false。If null or an empty string is passed in as the error parameter, the DataRow behaves as if no error was set and the HasErrors property will return false.

若要对整行设置自定义错误说明,请使用 RowError 属性。To set a custom error description on the whole row, use the RowError property.

若要确定列集合是否存在任何错误,请使用 HasErrors 方法。To determine whether any errors exist for the columns collection, use the HasErrors method.

若要清除列集合的所有错误,请使用 ClearErrors 方法。To clear all errors for the columns collection, use the ClearErrors method.

另请参阅

适用于