default.aspx.cs
来自「水晶报表详细资料水晶报表详细资料水晶报表详细资料」· CS 代码 · 共 69 行
CS
69 行
using System;
using System.Data;
using System.Configuration;
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 _Default : System.Web.UI.Page
{
SqlConnection myConn;
SqlCommand myCmd;
SqlDataAdapter adapter;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
myConn = new SqlConnection("server=a\\mr;database=master;UID=sa;PassWord=''");
string strSql = "Exec sp_helpdb";
adapter = new SqlDataAdapter(strSql, myConn);
ds = new DataSet();
adapter.Fill(ds);
this.DropDownList1.DataSource = ds.Tables[0].DefaultView;
this.DropDownList1.DataTextField = "name";
this.DropDownList1.DataBind();
myConn.Dispose();
adapter.Dispose();
ds.Dispose();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string strSql1 = "server=a\\mr;database='"+this.DropDownList1.SelectedValue+"';UID=sa;PassWord=''";
string strSql2 = "backup database "+this.DropDownList1.SelectedValue+" to disk='"+this.TextBox1.Text.Trim()+".bak'";
try
{
myConn = new SqlConnection(strSql1);
myCmd = new SqlCommand(strSql2, myConn);
myConn.Open();
string backFile = this.TextBox1.Text.Trim() + ".bak";
if (File.Exists(backFile))
{
Response.Write("<script>alert('此文件已存在,请重新输入!');location='Default.aspx'</script>");
return;
}
myCmd.ExecuteNonQuery();
Response.Write("<script>alert('备份数据成功!');location='Default.aspx'</script>");
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
Response.Write("<script>alert('备份数据失败!');location='Default.aspx'</script>");
}
finally
{
myConn.Close();
myConn.Dispose();
myCmd.Dispose();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?