ODBC Blob from Native to SQL

DroezelDroezel Member Posts: 7
I'm reading the Picture field from the native database, and inserting the value in an sql server 2005 image column.

The code I'm using:
While myReader.Read
   ...
   If myReader(i).GetType.ToString = "System.Byte[]" Then

       Dim imagedata() As Byte = CType(myReader(i), Byte())
       Dim myParameter As SqlParameter = New SqlParameter("@Image", SqlDbType.Image, imagedata.Length)

       myParameter.Value = imagedata
       sqlCmd.Parameters.Add(myParameter)
       sSQL += myReader.GetName(i) + "=@Image, "

   Else
    ...
   sqlCmd.CommandText = sSQL 
   sqlCmd.ExecuteNonQuery()

End While

Later on, I restore the image field from sql server to a bitmap again:
Dim image() As Byte = Nothing
image = CType(dr("Picture"), Byte())
Dim strfn As String = Convert.ToString(DateTime.Now.ToFileTime())
Dim fs As FileStream = New FileStream("C:\Temp\" + strfn + ".bmp", FileMode.CreateNew, FileAccess.Write)
fs.Write(image, 0, image.Length)
fs.Flush()
fs.Close()


Now there are some very weird things happening. Whatever the size of the original bitmap in the navision db. The resulting file is always 4Kb smaller. If I open the original and resulting file in a text editor, all seems equal except for the last part.

Files can be found here:

http://www.bored.be/stuff/original.bmp
http://www.bored.be/stuff/result.bmp

Any ideas why this is happening?
Taking first steps in Navision
Sign In or Register to comment.