NorthWind Database, can't view images

J

JP

In the table Employees of NorthWind database there is a column Photo
(data type: image). I want to convert the first row image into a jpg
file, but I can't open the file because is not a valid image. What I
am doing wrong?

this is my code...

using System;
using System.Data.SqlClient;
using System.IO;

namespace nwTestCS
{
class Program
{
static void Main(string[] args)
{
using (SqlConnection connection = new
SqlConnection(Properties.Settings.Default.dbStr)) {
connection.Open();
SqlCommand command = new SqlCommand("select photo from
Employees", connection);
File.WriteAllBytes(@"C:\photo.jpg",(byte[])
command.ExecuteScalar());
}
}
}
}
 
C

Cor Ligthert[MVP]

JP,

In the Northwind datatabase are Ole bytes array included.
To get the images you need an offset of 78 bytes.

Whatever.Write(ByteArray, 78, ByteArra.Length - 78)

Cor
 
J

JP

JP,

In the Northwind datatabase are Ole bytes array included.
To get the images you need an offset of 78 bytes.

Whatever.Write(ByteArray, 78, ByteArra.Length - 78)

Cor

JP said:
In the table Employees of NorthWind database there is a column Photo
(data type: image). I want to convert the first row image into a jpg
file, but I can't open the file because is not a valid image. What I
am doing wrong?
this is my code...
using System;
using System.Data.SqlClient;
using System.IO;
namespace nwTestCS
{
   class Program
   {
       static void Main(string[] args)
       {
           using (SqlConnection connection = new
SqlConnection(Properties.Settings.Default.dbStr)) {
               connection.Open();
               SqlCommand command = new SqlCommand("select photo from
Employees", connection);
               File.WriteAllBytes(@"C:\photo.jpg",(byte[])
command.ExecuteScalar());
           }
       }
   }
}

thanks! it worked
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top