asp.net我用代码新建了一个数据库,接下来建表的代码应该放哪啊
detailsview输入新建的数据库的信息,里有个插入和取消,我点插入就在ItemInserted事件中新建一个数据库,接下来我想在这个数据库中新建表,但是怎么试也不成功,不知道问题出在哪了
public partial class ProManagement_NewProgram : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString.Get("Project_ID") != null) { DetailsView1.DefaultMode = DetailsViewMode.Edit; } } protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e) { string str1; str1 = (DetailsView1.FindControl("TextBox1") as System.Web.UI.WebControls.TextBox).Text.ToString(); String str; SqlConnection myConn = new SqlConnection("Server=LIUKAI-THINK;Integrated security=SSPI;database=master"); str = "CREATE DATABASE "+str1+" ON PRIMARY " + "(NAME = str1_Data, " + "FILENAME = 'D:\\"+str1+".mdf', " + "SIZE = 3MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " + "LOG ON (NAME = MyDatabase_Log, " + "FILENAME = 'D:\\"+str1+".ldf', " + "SIZE = 1MB, " + "MAXSIZE = 5MB, " + "FILEGROWTH = 10%)"; SqlCommand myCommand = new SqlCommand(str, myConn); myConn.Open(); myCommand.ExecuteNonQuery(); if (myConn.State == ConnectionState.Open) { myConn.Close(); } EndEditing(); }
SqlConnection myConn = new SqlConnection("Server=LIUKAI-THINK;Integrated security=SSPI;database=master");string str2; str2 = "CREATE TABLE Project" + "Project_ID int," + "(Name nvarchar(256) NULL," + "Owner nvarchar(256) NULL," + "Description char(10) NULL" + "PathToDatabaseFiles nvarchar(256) NULL" + "AutoShrink int NULL" + "Epoch datetime NULL" + "State int NULL)";SqlCommand myCommand1 = new SqlCommand(str2, myConn);myConn.Open();myCommand.ExecuteNonQuery();myConn.Close();