如何在3层项目中创建备份时获得.bak扩展名

时间:2014-09-29 09:41:11

标签: c#

点击备份btn时打开了一个savefiledialog框,但我无法在保存类型时找到.bak扩展名 码: private void backupdb_Load(object sender,EventArgs e)
        {             label4.Visible = false;

        DataSet ds = SqlGetData.GetData1("select srvname  from sysservers  where srvproduct='SQL Server'");

        for (int m = 0; m < ds.Tables[0].Rows.Count; m++)
        {
            cbserver.Items.Add(ds.Tables[0].Rows[0][m].ToString());
        }
    } 

private void comboBox1_SelectedIndexChanged(object sender,EventArgs e)         {             cbdb.Items.Clear();             DataSet ds = SqlGetData.GetData1(“从sysdatabases中选择名称”);             for(int m = 0; m&lt; ds.Tables [0] .Rows.Count; m ++)             {                 cbdb.Items.Add((ds.Tables [0] .Rows [M] [0]的ToString())的ToString());             }         }

    private void button1_Click(object sender, EventArgs e)
    {

        blank("backup");


    }

    public void blank(string str)
    {
        if (string.IsNullOrEmpty(cbserver.Text) | string.IsNullOrEmpty(cbdb.Text))
        {

            label4.Visible = true;
            MessageBox.Show("Server Name & Database can not be Blank");
            return;

        }
        else
        {
            if (str == "backup")
            {
                saveFileDialog1.FileName = cbdb.Text;
                saveFileDialog1.ShowDialog();
                string s = null;
                s = saveFileDialog1.FileName;
                saveFileDialog1.Filter = "All Files|*.bak";
                query("Backup database " + cbdb.Text + " to disk='" + s + "'");

                label4.Visible = true;
                label4.Text = "Database BackUp has been created successful";



            }
        }

1 个答案:

答案 0 :(得分:0)

移动线条以在显示对话框之前将过滤器设置为

saveFileDialog1.Filter = "All Files|*.bak"
saveFileDialog1.ShowDialog();