SqlError.Message 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取对错误进行描述的文本。
public:
property System::String ^ Message { System::String ^ get(); };
public string Message { get; }
member this.Message : string
Public ReadOnly Property Message As String
属性值
描述错误的文本。 有关 SQL Server 生成的错误的详细信息,请参阅 数据库引擎事件和错误。
示例
以下示例显示 SqlError 集合中的每个 SqlErrorCollection 。
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