/// <summary> /// 创建数据库 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btndatabase_Click(object sender, EventArgs e) { string path = Directory.GetCurrentDirectory() + @"\App.config"; if (!Directory.Exists(path)) { //MessageBox.Show("cunzai"); } else { CreateXml(comboBox1.Text.Trim(), textdatabase.Text.Trim()); } string sql = string.Format("select * from master.dbo.sysdatabases where name = '{0}'", textdatabase.Text.Trim()); wznr_Servise wznrservise = new wznr_Servise(); DataTable dt = wznrservise.GetDataTable(sql); if (dt.Rows.Count > 0) { MessageBox.Show("数据库已存在!", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { try { string sql1 = " Create table test2Table( ID int IDENTITY PRIMARY KEY, Title varchar(255), Content ntext, keys varchar(255) )"; string sql2 = " CREATE TYPE test2Udt AS TABLE ( Title varchar(255), Content ntext, keys varchar(255) )"; wznrservise.ExecuteSql(sql1); wznrservise.ExecuteSql(sql2); } catch (SqlException ex) { MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } } //wznrservise.Exists(strsql.ToString()); //MessageBox.Show("创建成功!", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Information); }
//删除临时存储数据 private void button4_Click(object sender, EventArgs e) { string sql = "delete from test5Table"; try { wznr_Servise servise = new wznr_Servise(); int count = servise.ExecuteSql(sql); if (count > 0) { MessageBox.Show("数据删除成功!", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception) { throw; } }