This documentation is archived and is not being maintained.

SqlException.Errors Property

Gets a collection of one or more SqlError objects that give detailed information about exceptions generated by the .NET Framework Data Provider for SQL Server.

[Visual Basic]
Public ReadOnly Property Errors As SqlErrorCollection
[C#]
public SqlErrorCollection Errors {get;}
[C++]
public: __property SqlErrorCollection* get_Errors();
[JScript]
public function get Errors() : SqlErrorCollection;

Property Value

The collected instances of the SqlError class.

Remarks

The SqlErrorCollection class always contains at least one instance of the SqlError class.

This is a wrapper for SqlErrorCollection.

Example

[Visual Basic, C#, C++] The following example displays each SqlError within the SqlErrorCollection collection.

[Visual Basic] 
Public Sub DisplaySqlErrors(myException As SqlException)
    Dim i As Integer
    For i = 0 To myException.Errors.Count - 1
        MessageBox.Show("Index #" & i & ControlChars.NewLine & _
                        "Error: " & myException.Errors(i).ToString() & ControlChars.NewLine)
    Next i
End Sub 'DisplaySqlErrors

[C#] 
public void DisplaySqlErrors(SqlException myException) 
 {
    for (int i=0; i < myException.Errors.Count; i++)
    {
       MessageBox.Show("Index #" + i + "\n" +
            "Error: " + myException.Errors[i].ToString() + "\n");
    }
 }

[C++] 
public:
void DisplaySqlErrors(SqlException* myException) 
 {
    for (int i=0; i < myException->Errors->Count; i++)
    {
       MessageBox::Show(String::Format( S"Index #{0}\nError: {1}\n",
          __box(i), myException->Errors->Item[i] ));
    }
 }

[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

SqlException Class | SqlException Members | System.Data.SqlClient Namespace | SqlErrorCollection | SqlError

Show: