DataRow.GetColumnsInError Method ()


Gets an array of columns that have errors.

Namespace:   System.Data
Assembly:  System.Data (in System.Data.dll)

Public Function GetColumnsInError As DataColumn()

Return Value

Type: System.Data.DataColumn()

An array of DataColumn objects that contain errors.

The GetColumnsInError lets you reduce the number of DataColumn objects that must be processed for errors by returning only those columns that have an error. Errors can be set to individual columns with the SetColumnError method. To further reduce the number of processing, examine the HasErrors property of the DataRow class to determine whether a DataRow has errors before invoking GetColumnsInError.

Use the ClearErrors method to clear all errors on the row. This includes the RowError.

The following example uses the HasErrors to look for errors. If the row has errors, the GetColumnsInError method returns the array of columns with errors that can then be resolved. The ClearErrors method is then called to clear all errors.

Private Sub GetAllErrs(ByVal row As DataRow)
    ' Declare an array variable for DataColumn objects.
    Dim colArr() As DataColumn 

    ' If the Row has errors, check use GetColumnsInError.
    Dim i As Integer
    If row.HasErrors Then 
       ' Get the array of columns in error.
       colArr = row.GetColumnsInError()
       For i = 0 to colArr.GetUpperBound(0)
          ' Insert code to fix errors on each column.
       Next i

    ' Clear errors after reconciling.
    End If
 End Sub

.NET Framework
Available since 1.1
Return to top