public static void AddNewEntry(string text, string fileName)
{
string path = Directory.GetCurrentDirectory();
path = Path.Combine(path, fileName);
using (StreamWriter sw = new StreamWriter(path))
{
sw.Write(text);
}
FileInfo fi = new FileInfo(path);
if(fi.Exists)
{
byte[] bData = null;
// Read file data into buffer
using (FileStream fs = fi.OpenRead())
{
bData = new byte[fi.Length];
int nReadLength = fs.Read(bData, 0, (int)(fi.Length));
}
string strQuery = String.Format("INSERT INTO Files (content) VALUES (@filedata)");
var command = new oledb.OleDbCommand(strQuery, connection);
command.Parameters.AddWithValue("@filedata", bData);
connection.Open();
command.ExecuteNonQuery();
connection.Close();
}
File.Delete(path);
}I have a table named 'Files'. It has two atributes file_id(primary key, counter) and content(has type 'entry', I keep txt files in this field). As you can see I try to convert text file to binary and then I want to insert this binary file to the field 'content' into access database.
Please, help. Sincerely, Alex.