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生成的错误的详细信息,请参阅数据库引擎事件和错误

示例

以下示例显示 SqlError 集合中的每个 SqlErrorCollection

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

适用于