1个回答
展开全部
大概代码如下,你可以自己看下,相关联的操作流程你补充下,
string strg = Application.StartupPath.ToString();
strg = strg.Substring(0, strg.LastIndexOf("\\"));
strg = strg.Substring(0, strg.LastIndexOf("\\"));
strg += @"\Data";
string sqltxt = @"BACKUP DATABASE 数据库名 TO Disk='" + strg + "\\" + txtPath.Text + ".bak" + "'";
SqlConnection con = new SqlConnection(connectionString);
con.Open();
SqlCommand cmd = new SqlCommand(sqltxt, con);
cmd.ExecuteNonQuery();
con.Close();
if (MessageBox.Show("备份成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) == DialogResult.OK) {
this.Close(); }
string strg = Application.StartupPath.ToString();
strg = strg.Substring(0, strg.LastIndexOf("\\"));
strg = strg.Substring(0, strg.LastIndexOf("\\"));
strg += @"\Data";
string sqltxt = @"BACKUP DATABASE 数据库名 TO Disk='" + strg + "\\" + txtPath.Text + ".bak" + "'";
SqlConnection con = new SqlConnection(connectionString);
con.Open();
SqlCommand cmd = new SqlCommand(sqltxt, con);
cmd.ExecuteNonQuery();
con.Close();
if (MessageBox.Show("备份成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) == DialogResult.OK) {
this.Close(); }
追问
connectionString报错了,没定义,
txtPath.Text 这个是哪个控件的?
追答
额。。我才回来你就搞定了?呵呵。上面的比较基本,仔细看就懂了的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询