im trying to save an access database file by creating a new database file and save it anywhere as the user like and also name the file.
i tried using this code but it say 'the file cannot be access as it use by another process'. any idea?
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();
}