DataRow.SetColumnError Method

Definition

Sets the error description for a column.

Overloads

SetColumnError(DataColumn, String)

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)

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)

Parameters

column
DataColumn

The DataColumn to set the error description for.

error
String

The error description.

Examples

The 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

Remarks

To examine error descriptions, use the GetColumnError method.

To determine whether any errors exist for the columns collection, use the HasErrors property. Consequently, you can use the GetColumnsInError method to retrieve all the columns with errors.

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.

To set a custom error description on the whole row, use the RowError property.

To determine whether any errors exist for the columns collection, use the HasErrors method.

To clear all errors for the columns collection, use the ClearErrors method.

See also

Applies to

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)

Parameters

columnIndex
Int32

The zero-based index of the column.

error
String

The error description.

Exceptions

The columnIndex argument is out of range

Examples

The 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

Remarks

The method is used to set custom error descriptions on specified columns. You can use the ErrorProvider control to display the text of the error.

To examine error descriptions, use the GetColumnError method.

To determine whether any errors exist for the columns collection, use the HasErrors property. Consequently, you can use the GetColumnsInError method to retrieve all the columns with errors.

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.

To set a custom error description on the whole row, use the RowError property.

To clear all errors for the columns collection, use the ClearErrors method.

To set error text that applies to a whole row, set the RowError property.

See also

Applies to

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)

Parameters

columnName
String

The name of the column.

error
String

The error description.

Examples

The 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

Remarks

The name of a column is set with the ColumnName property of the DataColumn class.

To examine error descriptions, use the GetColumnError method.

To determine whether any errors exist for the columns collection, use the HasErrors property. Consequently, you can use the GetColumnsInError method to retrieve all the columns with errors.

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.

To set a custom error description on the whole row, use the RowError property.

To determine whether any errors exist for the columns collection, use the HasErrors method.

To clear all errors for the columns collection, use the ClearErrors method.

See also

Applies to