[/UseMoney]
[此贴子已经被作者于2007-1-22 20:31:05编辑过]
[此贴子已经被作者于2007-1-22 20:31:05编辑过]
[attach]14940[/attach]
我来发文字
//显示 Test是保存数据库的文件夹
private void button1_Click(object sender, System.EventArgs e)
{
listBox1.Items.AddRange(Directory.GetFiles(@"d:\test"));
listBox1.Items.AddRange(Directory.GetDirectories(@"d:\test"));
}
private void button6_Click(object sender, System.EventArgs e)
{
this.Close();
}
//清空
private void button2_Click(object sender, System.EventArgs e)
{
listBox1.Items.Clear();
}
//备份数据库
private void button4_Click(object sender, System.EventArgs e)
{ int i=DateTime.Now.Month;
string str;
if(i>=1 & i<=9)
{
str="0"+i.ToString();
}
else
str=i.ToString();
if (!File.Exists(@"D:\test\text"+DateTime.Now.Year.ToString()+str))
{
SqlCommand sqlCmd=new SqlCommand(@"Backup DataBase text To Disk='D:\test\text"+DateTime.Now.Year.ToString()+str+"'",sqlcon);
sqlCmd.ExecuteNonQuery();
MessageBox.Show("保存成功");
}
else
MessageBox.Show("已经保存过了");
}
//建数据库
private void button3_Click(object sender, System.EventArgs e)
{
string str;
str="if Exists (Select * from SysDataBases Where name='Example') "+
"Drop DataBase Example "+
"Create DataBase Example "+
"On "+
"( "+
"Name=Example_data, "+
@"FileName='D:\DataBase\Example_Data.mdf', "+
"filegrowth=1Mb, "+
"Size=5 "+
")";
SqlCommand sqlcom=new SqlCommand(str,sqlcon);
sqlcom.ExecuteNonQuery();
MessageBox.Show("成功");
}
//还原
private void button5_Click(object sender, System.EventArgs e)
{
mycon.close();
string str;
if (DateTime.Now.Month<=9)
str="0"+DateTime.Now.Month.ToString();
else
str=DateTime.Now.Month.ToString();
SqlCommand sqlcmd=new SqlCommand(@"Restore DataBase text From Disk='D:\test\text"+DateTime.Now.Year.ToString()+str+"'",sqlcon);
sqlcmd.ExecuteNonQuery();
MessageBox.Show("还原成功");
}
//建表
private void button7_Click(object sender, System.EventArgs e)
{
SqlConnection mycon=new SqlConnection("uid=sa;database=text");
mycon.Open();
string ok;
ok="if Exists (Select * from Sysobjects Where name='text1') "+
"Drop table text1 "+
"Create Table Text1"+
"("+
"AuID int Identity(1,1),"+
"TName varchar(10) ,"+
"TSex varchar(4),"+
"Remark varchar(200)"+
")";
SqlCommand sqlcom=new SqlCommand(ok,mycon);
sqlcom.ExecuteNonQuery();
}