共用方式為


SqlError.Message 屬性

定義

取得描述錯誤的文字。

public:
 property System::String ^ Message { System::String ^ get(); };
public string Message { get; }
member this.Message : string
Public ReadOnly Property Message As String

屬性值

描述錯誤的文字。 如需SQL Server所產生的錯誤詳細資訊,請參閱Database Engine 事件和錯誤

範例

下列範例會顯示集合內的每一個 SqlErrorSqlErrorCollection

using Microsoft.Data.SqlClient;
using System.Collections.Generic;
using System.Text;

namespace Classic_WebData_SqlError.StateCS
{
    class Program
    {
        static void Main()
        {
            //DisplaySqlErrors();
        }

        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();
        }
    }
}

適用於