我想在数据库备份中选择路径时从数据库选择中获取数据库名称...例如:我选择了数据库名称'Sample'的名称,然后单击Browse按钮并选择我想要的路径备份...现在,我想在位置后选择数据库名称Sample ... 对于实例:C:\ Users \ Abc \ Desktop \ Sample ...帮助我在文本框中获取所选的数据库名称。
备份的浏览按钮代码:
private void btnBrowseBa_Click(object sender, EventArgs e)
{
FolderBrowserDialog dlg = new FolderBrowserDialog();
if(dlg.ShowDialog()== DialogResult.OK)
{
txtLocBa.Text = dlg.SelectedPath;
}
}
答案 0 :(得分:2)
FolderBrowserDialog dlg = new FolderBrowserDialog();
if(dlg.ShowDialog()== DialogResult.OK)
{
var database = yourDatabaseComboBox.SelectedItem.ToString();
var extension= "bak";
var databaseFileName = string.Format("{0}.{1}", database, extension);
txtLocBa.Text = System.IO.Path.Combine(dlg.SelectedPath, databaseFileName);
}
答案 1 :(得分:0)
尝试这将获得路径:
path = Path.Combine(backupPath, databaseNameComboBox.Text);
答案 2 :(得分:0)
好吧,取决于你的组合名称是什么:
private void btnBrowseBa_Click(object sender, EventArgs e)
{
string path = "";
FolderBrowserDialog dlg = new FolderBrowserDialog();
if(dlg.ShowDialog()== DialogResult.OK)
{
path = Path.Combine(dlg.SelectedPath, comboBox.Text);
}
}
答案 3 :(得分:0)
只是连接:
txtLocBa.Text = dlg.SelectedPath + @"\" + comboBox1.Text