我试图通过创建一个新的数据库文件来保存访问数据库文件,并将其保存在用户喜欢的任何位置并命名该文件。
我尝试使用此代码,但它说'该文件无法访问,因为它由另一个进程使用'。任何想法?
private void btnSelectDatabase_Click(object sender, EventArgs e)
{
ofdMain.ShowDialog();
lblDatabase.Text = ofdMain.FileName;
}
private void btnLoadDatabase_Click(object sender, EventArgs e)
{
try
{
test = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=" + lblDatabase.Text);
test.Open();
refresh();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnSave_Click_1(object sender, EventArgs e)
{
sfdMain.ShowDialog();
}
private void sfdMain_FileOk(object sender, CancelEventArgs e)
{
StreamReader read = new StreamReader(lblDatabase.Text);
Stream s = File.Open(sfdMain.FileName, FileMode.CreateNew);
StreamWriter writer = new StreamWriter(s);
writer.Close();
}