主题:[讨论]求助Windows Forms问题
小弟刚来,有个问题想问下各位高手
请看以下代码:
try
{
sd.InitialDirectory = Application.StartupPath + "\\";//默认路径为D盘
sd.Filter = "备份文件(*.bak)|*.bak|所有文件(*.*)|*.*";//筛选器,文件类型
if (sd.ShowDialog() == DialogResult.OK)
{
if (!File.Exists(sd.FileName.ToString()))
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=.;uid=sa;pwd=;database='" + this.db_EquipmentMS.Text + "";
con.Open();
SqlCommand com = new SqlCommand();
this.textBox1.Text = sd.FileName.ToString();
com.CommandText = "BACKUP DATABASE" + this.db_EquipmentMS.Text + "TO DISK='" + sd.FileName.ToString() + "'";
com.Connection = con;
com.ExecuteNonQuery();
con.Close();
con.Dispose();
MessageBox.show("数据备份成功!");
}
else
{
MessageBox.Show("请重新命名!");
}
}
}
catch (Exception k)
{
MessageBox.Show(k.Message);
return;
}
注:
控件类型 控件名称 用途
TextBox textBox1 显示备份文件的路径
ComboBox comboBox1 显示数据库名称
Button button1 备份数据库
SaveFileDialog sa “另存为”对话框
上面的代码执行以后出现了10个错误
[img]http://img.blog.163.com/photo/J3MUMJ8RZcT2Z4aILwAVAg==/4506977327091346717.jpg[/img]
谁可以帮我解决一下这些问题啊
请看以下代码:
try
{
sd.InitialDirectory = Application.StartupPath + "\\";//默认路径为D盘
sd.Filter = "备份文件(*.bak)|*.bak|所有文件(*.*)|*.*";//筛选器,文件类型
if (sd.ShowDialog() == DialogResult.OK)
{
if (!File.Exists(sd.FileName.ToString()))
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=.;uid=sa;pwd=;database='" + this.db_EquipmentMS.Text + "";
con.Open();
SqlCommand com = new SqlCommand();
this.textBox1.Text = sd.FileName.ToString();
com.CommandText = "BACKUP DATABASE" + this.db_EquipmentMS.Text + "TO DISK='" + sd.FileName.ToString() + "'";
com.Connection = con;
com.ExecuteNonQuery();
con.Close();
con.Dispose();
MessageBox.show("数据备份成功!");
}
else
{
MessageBox.Show("请重新命名!");
}
}
}
catch (Exception k)
{
MessageBox.Show(k.Message);
return;
}
注:
控件类型 控件名称 用途
TextBox textBox1 显示备份文件的路径
ComboBox comboBox1 显示数据库名称
Button button1 备份数据库
SaveFileDialog sa “另存为”对话框
上面的代码执行以后出现了10个错误
[img]http://img.blog.163.com/photo/J3MUMJ8RZcT2Z4aILwAVAg==/4506977327091346717.jpg[/img]
谁可以帮我解决一下这些问题啊