Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Accessing Data
 How to: Locate Rows that Have Error...

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
Data Access in Client and Middle-Tier Programming 
How to: Locate Rows that Have Errors 

When working with individual columns and rows of data, there may be times when a record contains an error. You can Check the HasErrors property to determine if errors exist in a DataSet, DataTable, or DataRow.

To locate a row that has errors

  1. Check the HasErrors property to see if there are any errors in the dataset.

  2. If the HasErrors property is true, iterate through the collections of tables, then the rows to find the row with the error.

    Visual Basic
    Private Sub FindErrors()
        Dim table As Data.DataTable
        Dim row As Data.DataRow
    
        If DataSet1.HasErrors Then
    
            For Each table In DataSet1.Tables
                If table.HasErrors Then
    
                    For Each row In table.Rows
                        If row.HasErrors Then
    
                            ' Process error here.
                        End If
                    Next
                End If
            Next
        End If
    End Sub
    
    C#
    private void FindErrors() 
    {
        if (dataSet1.HasErrors)
        {
            foreach (DataTable table in dataSet1.Tables)
            {
                if (table.HasErrors)
                {
                    foreach (DataRow row in table.Rows)
                    {
                        if (row.HasErrors)
                        {
                            // Process error here.
                        }
                    }
                }
            }
        }
    }
    
    J#
    private void Find_Errors()
    {
        if (dataSet1.get_HasErrors())
        {
            // for each table
            for (int i = 0; i < dataSet1.get_Tables().get_Count(); i++)
            {
                DataTable table = dataSet1.get_Tables().get_Item(i);
                
                if (table.get_HasErrors())
                {
    
                    // for each row
                    for (int j = 0; j < table.get_Rows().get_Count(); j++)
                    {
                        DataRow row = table.get_Rows().get_Item(j);
    
                        if (row.get_HasErrors())
                        {
                            // Process error here.
                        }
                    }
                }
            }
        }
    }
    

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker