⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logvendormodification.cs

📁 sqlserver scripts from ch 14 in zip files
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.SqlServer.Server;
using System.Transactions;

public partial class Triggers
{
    [Microsoft.SqlServer.Server.SqlTrigger(Name = "LogVendorModification", Target = "[Purchasing].[Vendor]", Event = "FOR UPDATE")]
    public static void LogVendorModification()
    {
        using (SqlConnection connection = new SqlConnection(@"context connection=true"))
        {
            SqlCommand command;
            SqlDataReader reader;
            string emailAddress;

            // Open the connection.
            connection.Open();

            // Get the inserted value.
            command = new SqlCommand(@"SELECT PurchasingWebServiceURL FROM INSERTED", connection);
            reader = command.ExecuteReader();
            reader.Read();
            emailAddress = (string)reader[0];
            reader.Close();

            // Rollback the transaction if an invalid email address was inserted.
            if (emailAddress.Length < 4)
            {
                Transaction.Current.Rollback();
            }

            // Close the connection.
            connection.Close();
        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -