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


                .......
                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;
                    }
                } 

你可能感兴趣的:(C#中使用SQLDMO的StoredProcedure对象(存储过程)创建数据表)