I have some task. I must to implement a text editor with the ability to save / download files to / from the ms access database, but i don't know how it to do. There is my try(it doesn't work. only save files). I know, it's stupid, but..
OleDbCommand cmd = new OleDbCommand();
OleDbConnection cn = new OleDbConnection(
@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=..\..\Database1.accdb;Persist Security Info=True");
private void Button_Click_2(object sender, RoutedEventArgs e)
{
if(textBox1.Text != null)
{
FileInfo file = new FileInfo(textBox1.Text.ToString() + ".dat");
using (BinaryWriter bw = new BinaryWriter(file.OpenWrite()))
{
string text = textBox2.Text.ToString();
bw.Write(text);
try
{
cn.Open();
cmd.CommandText = "INSERT INTO info ( files.FileData ) values (@file)";
cmd.Parameters.Add("@file", file);
cmd.ExecuteNonQuery();
cn.Close();
}
catch (Exception ex)
{
cn.Close();
MessageBox.Show(ex.Message.ToString());
}
textBox1.Text = null;
textBox2.Text = null;
}
}
}
Is there any way to directly upload files to the database?