📄 index1.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient; //引用命名空间
using System.IO; //引用命名空间
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string cmdtxt1 = "Server=(local);DataBase=master;Uid=sa;Pwd=";
string cmdtxt2 = "Exec sp_helpdb";
SqlConnection Con = new SqlConnection(cmdtxt1);
Con.Open();
if (!Page.IsPostBack)
{
SqlCommand mycommand = new SqlCommand(cmdtxt2, Con);
SqlDataReader dr = mycommand.ExecuteReader();
this.dropDatabase.DataSource = dr;
this.dropDatabase.DataTextField = "name";
this.dropDatabase.DataBind();
dr.Close();
string cmdtxt3 = "use " + this.dropDatabase.SelectedValue + " SELECT * FROM " + this.dropDatabase.SelectedValue + ".dbo.sysobjects";
cmdtxt3 += " WHERE xtype='U' AND STATUS>=0";
SqlCommand mycommand1 = new SqlCommand(cmdtxt3, Con);
SqlDataReader dr1 = mycommand1.ExecuteReader();
this.dropTable.DataSource = dr1;
this.dropTable.DataTextField = "name";
this.dropTable.DataBind();
dr1.Close();
Con.Close();
}
if (this.RadioButtonList1.SelectedIndex == 1)
{
this.Panel7.Visible = false;
this.Panel8.Visible = true;
this.Panel9.Visible = false;
this.Panel10.Visible = true;
}
else
{
this.Panel7.Visible = true;
this.Panel8.Visible = false;
this.Panel9.Visible = true;
this.Panel10.Visible = false;
}
}
protected void btnBackup_Click(object sender, EventArgs e)
{
string cmdtxt1 = "Server=(local);Database=master;Uid=sa;Pwd='"+this.txtPwd.Text.Trim()+"'";
string cmdtxt2 = "USE master EXEC xp_cmdshell 'bcp "+this.dropDatabase.SelectedValue+".dbo."+this.dropTable.SelectedValue+"";
cmdtxt2 += " out "+this.txtPath.Text.Trim()+".xls -c -q -S. -Usa -P"+this.txtPwd.Text.Trim()+"'";
SqlConnection Con;
try
{
Con = new SqlConnection(cmdtxt1);
Con.Open();
SqlCommand Com = new SqlCommand(cmdtxt2, Con);
Com.ExecuteNonQuery();
Con.Close();
Response.Write("<script language=javascript>alert('备份数据成功!');location='Index1.aspx'</script>");
}
catch (Exception ms)
{
Response.Write(ms.Message);
Response.Write("<script language=javascript>alert('备份数据失败!');location='Index1.aspx'</script>");
}
}
protected void btnRestore_Click(object sender, EventArgs e)
{
string cmdtxt1 = "Server=(local);Database=master;Uid=sa;Pwd='" + this.txtPwd.Text.Trim() + "'";
string cmdtxt2 = "USE master EXEC xp_cmdshell 'bcp " + this.dropDatabase.SelectedValue + ".dbo." + this.dropTable.SelectedValue + "";
cmdtxt2 += " in " + this.fileShow.PostedFile.FileName + " -c -q -S. -Usa -P" + this.txtPwd.Text.Trim() + "'";
SqlConnection Con;
try
{
Con = new SqlConnection(cmdtxt1);
Con.Open();
SqlCommand Com = new SqlCommand(cmdtxt2, Con);
Com.ExecuteNonQuery();
Con.Close();
Response.Write("<script language=javascript>alert('还原数据成功!');location='Index1.aspx'</script>");
}
catch (Exception ms)
{
Response.Write(ms.Message);
Response.Write("<script language=javascript>alert('还原数据失败!');location='Index1.aspx'</script>");
}
}
protected void dropDatabase_SelectedIndexChanged(object sender, EventArgs e)
{
string cmdtxt1 = "Server=(local);DataBase=master;Uid=sa;Pwd=";
SqlConnection Con = new SqlConnection(cmdtxt1);
Con.Open();
string cmdtxt3 = "use " + this.dropDatabase.SelectedValue + " SELECT * FROM " + this.dropDatabase.SelectedValue + ".dbo.sysobjects";
cmdtxt3 += " WHERE xtype='U' AND STATUS>=0";
SqlCommand mycommand1 = new SqlCommand(cmdtxt3, Con);
SqlDataReader dr1 = mycommand1.ExecuteReader();
this.dropTable.DataSource = dr1;
this.dropTable.DataTextField = "name";
this.dropTable.DataBind();
dr1.Close();
Con.Close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -