SqlErrorCollection Class
Collects all errors generated by the .NET Framework Data Provider for SQL Server. This class cannot be inherited.
For a list of all members of this type, see SqlErrorCollection Members.
System.Object
System.Data.SqlClient.SqlErrorCollection
[Visual Basic] <Serializable> NotInheritable Public Class SqlErrorCollection Implements ICollection, IEnumerable [C#] [Serializable] public sealed class SqlErrorCollection : ICollection, IEnumerable [C++] [Serializable] public __gc __sealed class SqlErrorCollection : public ICollection, IEnumerable [JScript] public Serializable class SqlErrorCollection implements ICollection, IEnumerable
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
This class is created by SqlException to collect instances of the SqlError class. SqlErrorCollection always contains at least one instance of the SqlError class.
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
in the upper-left corner of the page.
Requirements
Namespace: System.Data.SqlClient
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
Assembly: System.Data (in System.Data.dll)
See Also
SqlErrorCollection Members | System.Data.SqlClient Namespace | SqlError | SqlException