SqlException.LineNumber プロパティ
アセンブリ: System.Data (system.data.dll 内)



SqlErrorCollection コレクション内の各 SqlError を表示する例を次に示します。
Public Sub ShowSqlException(ByVal connectionString As String) Dim queryString As String = "EXECUTE NonExistantStoredProcedure" Dim errorMessages As New StringBuilder() Using connection As New SqlConnection(connectionString) Dim command As New SqlCommand(queryString, connection) Try command.Connection.Open() command.ExecuteNonQuery() Catch ex As SqlException Dim i As Integer For i = 0 To ex.Errors.Count - 1 errorMessages.Append("Index #" & i.ToString() & ControlChars.NewLine _ & "Message: " & ex.Errors(i).Message & ControlChars.NewLine _ & "LineNumber: " & ex.Errors(i).LineNumber & ControlChars.NewLine _ & "Source: " & ex.Errors(i).Source & ControlChars.NewLine _ & "Procedure: " & ex.Errors(i).Procedure & ControlChars.NewLine) Next i Console.WriteLine(errorMessages.ToString()) End Try End Using End Sub
public static void ShowSqlException(string connectionString) { string queryString = "EXECUTE NonExistantStoredProcedure"; StringBuilder errorMessages = new StringBuilder(); using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(queryString, connection); try { command.Connection.Open(); command.ExecuteNonQuery(); } catch (SqlException ex) { for (int i = 0; i < ex.Errors.Count; i++) { errorMessages.Append("Index #" + i + "\n" + "Message: " + ex.Errors[i].Message + "\n" + "LineNumber: " + ex.Errors[i].LineNumber + "\n" + "Source: " + ex.Errors[i].Source + "\n" + "Procedure: " + ex.Errors[i].Procedure + "\n"); } Console.WriteLine(errorMessages.ToString()); } } }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からSqlException.LineNumber プロパティを検索する場合は、下記のリンクをクリックしてください。

- SqlException.LineNumber プロパティのページへのリンク