T
TakeshiKitano
Guest
Hi all,
I am trying to select a file, then store it to database and then read it again and show it.
I have done (I think) first part => to store file into database
But how to read this file from database and show it?
So my code of how to sotre file into database .. please if it is wrong, tell me, thanks
string item = String.Empty;
item = (dtgDocuments.SelectedItem as Documents).path.ToString(); }
byte[] file;
using (var stream = new FileStream(item, FileMode.Open, FileAccess.Read))
{
using (var reader = new BinaryReader(stream))
{
file = reader.ReadBytes((int)stream.Length);
}
}
using (SQLiteConnection con = new SQLiteConnection(conString))
{
con.Open();
using (SQLiteCommand cmd = new SQLiteCommand("INSERT INTO Documents (document) Values(@document)", con))
{
cmd.Parameters.AddWithValue("@document", file);
cmd.ExecuteNonQuery();
}
}
Continue reading...
I am trying to select a file, then store it to database and then read it again and show it.
I have done (I think) first part => to store file into database
But how to read this file from database and show it?
So my code of how to sotre file into database .. please if it is wrong, tell me, thanks
string item = String.Empty;
item = (dtgDocuments.SelectedItem as Documents).path.ToString(); }
byte[] file;
using (var stream = new FileStream(item, FileMode.Open, FileAccess.Read))
{
using (var reader = new BinaryReader(stream))
{
file = reader.ReadBytes((int)stream.Length);
}
}
using (SQLiteConnection con = new SQLiteConnection(conString))
{
con.Open();
using (SQLiteCommand cmd = new SQLiteCommand("INSERT INTO Documents (document) Values(@document)", con))
{
cmd.Parameters.AddWithValue("@document", file);
cmd.ExecuteNonQuery();
}
}
Continue reading...