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)

Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs

Sets the error description for a column specified as a DataColumn.

C#
public void SetColumnError(System.Data.DataColumn column, string? error);
C#
public void SetColumnError(System.Data.DataColumn column, string error);

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.

C#
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));
}

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

.NET 9 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

SetColumnError(Int32, String)

Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs

Sets the error description for a column specified by index.

C#
public void SetColumnError(int columnIndex, string? error);
C#
public void SetColumnError(int columnIndex, string error);

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.

C#
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));
}

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

.NET 9 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

SetColumnError(String, String)

Source:
DataRow.cs
Source:
DataRow.cs
Source:
DataRow.cs

Sets the error description for a column specified by name.

C#
public void SetColumnError(string columnName, string? error);
C#
public void SetColumnError(string columnName, string error);

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.

C#
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));
}

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

.NET 9 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1