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

📄 setupforeignkey.cs

📁 Microsoft Mobile Development Handbook的代码,有C#,VB,C++的
💻 CS
字号:
using System;
using System.Data.SqlServerCe;
using System.IO;
using System.Reflection;

namespace MobileDevelopersHandbook
{
    class SetupForeignKey
    {
        public static void DefineKey()
        {
            // Setup the connection string
            string databasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
            string connString = "Data Source=" + databasePath + 
                "\\MyDatabase.sdf; Password=MobileP@ssw0rd";

            string commandText = "ALTER TABLE Product " +
                "ADD CONSTRAINT Product_ProductCategory_FK " +
                "FOREIGN KEY (ProductCategoryID) REFERENCES ProductCategory(ProductCategoryID) " +
                "ON DELETE CASCADE " +
                "ON UPDATE CASCADE";

            using (SqlCeConnection conn = new SqlCeConnection(connString))
            {
                using (SqlCeCommand cmd = new SqlCeCommand(commandText, conn))
                {
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }
            }
        }
    }
}

⌨️ 快捷键说明

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