SqlError.LineNumber Property

Definition

从包含错误的 Transact-SQL 批命令或存储过程中获取行号。Gets the line number within the Transact-SQL command batch or stored procedure that contains the error.

public:
 property int LineNumber { int get(); };
public int LineNumber { get; }
member this.LineNumber : int
Public ReadOnly Property LineNumber As Integer

Property Value

Int32

Transact-SQL 批命令或存储过程内包含错误的行号。The line number within the Transact-SQL command batch or stored procedure that contains the error.

Examples

下面的示例显示 SqlErrorCollection 集合中的每个 SqlErrorThe following example displays each SqlError within the SqlErrorCollection collection.

public void DisplaySqlErrors(SqlException exception)
{
    for (int i = 0; i < exception.Errors.Count; i++)
    {
        Console.WriteLine("Index #" + i + "\n" +
            "Source: " + exception.Errors[i].Source + "\n" +
            "Number: " + exception.Errors[i].Number.ToString() + "\n" +
            "State: " + exception.Errors[i].State.ToString() + "\n" +
            "Class: " + exception.Errors[i].Class.ToString() + "\n" +
            "Server: " + exception.Errors[i].Server + "\n" +
            "Message: " + exception.Errors[i].Message + "\n" +
            "Procedure: " + exception.Errors[i].Procedure + "\n" +
            "LineNumber: " + exception.Errors[i].LineNumber.ToString());
    }
    Console.ReadLine();
}
Public Sub DisplaySqlErrors(ByVal exception As SqlException)
    Dim i As Integer

    For i = 0 To exception.Errors.Count - 1
        Console.WriteLine(("Index #" & i & ControlChars.NewLine & _
            "Source: " & exception.Errors(i).Source & ControlChars.NewLine & _
            "Number: " & exception.Errors(i).Number.ToString() & ControlChars.NewLine & _
            "State: " & exception.Errors(i).State.ToString() & ControlChars.NewLine & _
            "Class: " & exception.Errors(i).Class.ToString() & ControlChars.NewLine & _
            "Server: " & exception.Errors(i).Server & ControlChars.NewLine & _
            "Message: " & exception.Errors(i).Message & ControlChars.NewLine & _
            "Procedure: " & exception.Errors(i).Procedure & ControlChars.NewLine & _
            "LineNumber: " & exception.Errors(i).LineNumber.ToString()))
    Next i
    Console.ReadLine()
End Sub

Remarks

行号从1开始。Line numbering starts at 1. 如果该值为0,则行号不适用。If the value is 0, the line number is not applicable.

有关 SQL Server 生成的错误的详细信息,请参阅数据库引擎事件和错误For more information on errors generated by SQL Server, see Database Engine Events and Errors.

Applies to

See also