Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>using (var connection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\BlankDatabase.mdb")) { connection.Open(); // Create table using (var command = connection.CreateCommand()) { command.CommandText = @" CREATE TABLE FileTable ( FileName VARCHAR(255), File IMAGE) "; command.ExecuteNonQuery(); } var imageContent = File.ReadAllBytes(@"C:\logo.png"); // upload image to the table using (var command = connection.CreateCommand()) { command.CommandText = @" INSERT INTO FileTable (FileName, File) VALUES (@FileName, @File) "; command.Parameters.AddWithValue("@FileName", "Logo"); command.Parameters.AddWithValue("@File", imageContent); command.ExecuteNonQuery(); } // retreive image from the table using (var command = connection.CreateCommand()) { command.CommandText = @" SELECT File FROM FileTable WHERE FileName = 'Logo' "; var readImageContent = (byte[])command.ExecuteScalar(); File.WriteAllBytes(@"C:\logo1.png", readImageContent); } // alter image from the table using (var command = connection.CreateCommand()) { command.CommandText = @" UPDATE FileTable SET File = @File WHERE FileName = 'Logo' "; command.Parameters.AddWithValue("@File", imageContent); command.ExecuteNonQuery(); } // delete image from the table using (var command = connection.CreateCommand()) { command.CommandText = @" DELETE FROM FileTable WHERE FileName = 'Logo' "; command.ExecuteNonQuery(); } } </code></pre> <p>In this code <code>BlankDatabase.mdb</code> is an empty MS Access database file.</p> <p><strong>[Edit]</strong></p> <p>When you saved image to the database, as shown above you can retrieve image bytes as shown above:</p> <p>You can construct <code>Image</code> from image bytes like this:</p> <pre><code>var imageConverter = new ImageConverter(); pictureBox1.Image = (Image)imageConverter.ConvertFrom(fileContent); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload