C#中使用SQLDMO的StoredProcedure对象(存储过程)创建数据表「建议收藏」

2022-09-18 10:44:04 浏览数 (2)

大家好,又见面了,我是你们的朋友全栈君。

……. SQLDMO.StoredProcedure strProc = new SQLDMO.StoredProcedure(); // Assign a name to stored procedure strProc.Name = “createCustomerTable”; // Write a Stored Procedure Script and pass it as a string. strProc.Text = “CREATE procedure createCustomerTable as begin ” “CREATE TABLE [ChangeMemberID] ([CusID] [int] NOT NULL ,[ChangeDate] [smalldatetime] NULL ,” “[MIDO] [varchar] (6) COLLATE Chinese_PRC_CI_AS NULL ,” “[MIDN] [varchar] (6) COLLATE Chinese_PRC_CI_AS NULL ) ON [PRIMARY] ” “END”; // Add the Stored Procedure to Database nDB.StoredProcedures.Add(strProc); // Execute the stored procedure to create table nDB.ExecuteImmediate(“createCustomerTable”, 0, 0);

/* Remove the stored procedure from database. The index starts from 1.*/ foreach (SQLDMO.StoredProcedure tmpSP in nDB.StoredProcedures) { //find the StoredProcedure named “createCustomerTable” if (tmpSP.Name == “createCustomerTable”) { nDB.StoredProcedures.Remove(tmpSP.ID, “”); break; } }

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/164513.html原文链接:https://javaforall.cn

0 人点赞