Export (0) Print
Expand All

DataRow.RowError Property

Gets or sets the custom error description for a row.

[Visual Basic]
Public Property RowError As String
[C#]
public string RowError {get; set;}
[C++]
public: __property String* get_RowError();
public: __property void set_RowError(String*);
[JScript]
public function get RowError() : String;
public function set RowError(String);

Property Value

The text describing an error.

Remarks

Uses the HasErrors property to first determine if a DataRow contains errors.

Example

[Visual Basic, C#, C++] The following example sets error text for ten rows of a table displayed in a DataGrid control.

[Visual Basic] 
Private Sub SetRowErrors(ByVal myTable As DataTable)
    ' Set error text for ten rows. 
    Dim i As Integer
    For i = 0 to 10
     ' Insert column 1 value into each error.
       myTable.Rows(i).RowError = "ERROR: " & myTable.Rows(i)(1).ToString()
    Next
    ' Get the DataSet for the table, and test it for errors.
    Dim myDataSet As DataSet 
    myDataSet = myTable.DataSet
    TestForErrors(myDataSet)
 End Sub
 
 Private Sub TestForErrors(ByVal myDataSet As DataSet)
    ' Test for errors. If DataSet has errors, test each table.
    If myDataSet.HasErrors
       Dim tempDataTable As DataTable
       For Each tempDataTable in myDataSet.Tables
          ' If the table has errors, then print them.
          If(tempDataTable.HasErrors) Then PrintRowErrs(tempDataTable)
       Next
    ' Refresh the DataGrid to see the error-marked rows.
       DataGrid1.Refresh()
    End If
 End Sub
 
 Private Sub PrintRowErrs(ByVal myTable As DataTable)
    Dim myDataRow As DataRow
    For Each myDataRow in myTable.Rows
       If(myDataRow.HasErrors) Then
          Console.WriteLine(myDataRow.RowError)
       End If
    Next
 End Sub

[C#] 
private void SetRowErrors(DataTable myTable){
    // Set error text for ten rows. 
    for(int i = 0; i < 10; i++){
       // Insert column 1 value into each error.
       myTable.Rows[i].RowError = "ERROR: " + myTable.Rows[i][1];
    }
    // Get the DataSet for the table, and test it for errors.
    DataSet myDataSet = myTable.DataSet;
    TestForErrors(myDataSet);
 }
 
 private void TestForErrors(DataSet myDataSet){
    // Test for errors. If DataSet has errors, test each table.
    if(myDataSet.HasErrors){
       foreach(DataTable tempDataTable in myDataSet.Tables){
       // If the table has errors, then print them.
       if(tempDataTable.HasErrors) PrintRowErrs(tempDataTable);
    }
    // Refresh the DataGrid to see the error-marked rows.
       dataGrid1.Refresh();
    }
 }
 
 private void PrintRowErrs(DataTable myTable){
    foreach(DataRow myDataRow in myTable.Rows){
       if(myDataRow.HasErrors) {
          Console.WriteLine(myDataRow.RowError);
       }
    }
 }

[C++] 
private:
void SetRowErrors(DataTable* myTable){
    // Set error text for ten rows. 
    for(int i = 0; i < 10; i++){
       // Insert column 1 value into each error.
       myTable->Rows->Item[i]->RowError = String::Format( S"ERROR: {0}", myTable->Rows->Item[i]->Item[1] );
    }
    // Get the DataSet for the table, and test it for errors.
    DataSet* myDataSet = myTable->DataSet;
    TestForErrors(myDataSet);
 }
 
 void TestForErrors(DataSet* myDataSet){
    // Test for errors. If DataSet has errors, test each table.
    if(myDataSet->HasErrors){
       System::Collections::IEnumerator* myEnum = myDataSet->Tables->GetEnumerator();
       while (myEnum->MoveNext())
       {
          DataTable* tempDataTable = __try_cast<DataTable*>(myEnum->Current);
       // If the table has errors, then print them.
       if(tempDataTable->HasErrors) PrintRowErrs(tempDataTable);
    }
    // Refresh the DataGrid to see the error-marked rows.
       dataGrid1->Refresh();
    }
 }
 
 void PrintRowErrs(DataTable* myTable){
    System::Collections::IEnumerator* myEnum1 = myTable->Rows->GetEnumerator();
    while (myEnum1->MoveNext())
    {
       DataRow* myDataRow = __try_cast<DataRow*>(myEnum1->Current);
       if(myDataRow->HasErrors) {
          Console::WriteLine(myDataRow->RowError);
       }
    }
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataRow Class | DataRow Members | System.Data Namespace | SetColumnError | HasErrors

Show:
© 2014 Microsoft