Hi all,

I'm really need your help regarding how to insert image into blob field in Firebird/Interbase 6.0....I'm using connection trough ODBC ( "DRIVER=Firebird/InterBase(r) driver;UID=SYSDBA;PWD=masterkey;DBNAME=c:\ibss\database\ibssdemo.gdb "

I can manage to pull into SQL Server 2008..but not for Interbase....can anyone help me...here my code that giving error...(SQL -104)

If Not myReader.Item("PHOTO").Equals(DBNull.Value) Then

                    ' Get the image from the database.
                    Dim imagedata() As Byte = CType(myReader.Item("PHOTO"), Byte())



                    Dim K As Long
                    '      '
                    K = UBound(imagedata)
                    '    'Simpan data temp folder
                    '
                    Dim fs As New FileStream("" & myReader.Item(0) & ".jpg", FileMode.OpenOrCreate, FileAccess.Write)
                    '
                    fs.Write(imagedata, 0, K)
                    '
                    fs.Close()


 Dim imgName As String = ("" & myReader.Item(0) & ".jpg")
   Dim fs1 As FileStream = New FileStream(imgName, FileMode.Open, FileAccess.Read)


                       Dim picByte As Byte() = New Byte(fs1.Length - 1) {}

                      fs1.Read(picByte, 0, System.Convert.ToInt32(fs1.Length))

                     fs1.Close()

   Dim Str As String = "update CARDHOLDER set PHOTO = (" & "@Img) where CARDHOLDERID = '" & myReader.Item(0).ToString & "'  "
                 Dim cmd As New OleDbCommand(Str, cn)
                    cmd.Parameters.Add("@Img", odbcType.Binary)
                    cmd.Parameters.Item("@Img").Value = image
cn.open
  cmd.ExecuteNonQuery()
cn close
end if
...

Dim byteArray() as byte=System.IO.File.ReadAllBytes("c:\x.png")

Dim Str As String = "update CARDHOLDER set PHOTO = (@Img) where CARDHOLDERID =@Card"

Dim cmd As New OleDbCommand(Str, cn)

cmd.Parameters.Add("@Img", odbcType.Binary,byteArray.Length).Value=byteArray
cmd.Parameters.Add("@Card",odbcType.Varchar,20).value=myReader.Item(0).ToString()

cn.open
cmd.ExecuteNonQuery()
cn close

Got this error bro :
Failed to convert parameter value from a Byte[] to a Int16.
Can u help me..

Ok..i can managed to do ...so i share it to whom want it....

Dim photofilepath As String = ("" & myReader.Item(0) & ".jpg")
                    Dim photo() As Byte = GetPhoto(photofilepath)
                    '  Dim name As String = photoFilePath.Substring(photoFilePath.LastIndexOf("\") + 1)
                    '  Dim nwindConn As FbConnection = New FbConnection(myConnection)
                    '  n()
                    Dim addEmp As New FbCommand
                    addEmp = New FbCommand("update  cardholder set PHOTO = (@PHOTO)  where CARDHOLDERID = '" & myReader.Item(0).ToString & "'  ", myConnection)
                    '  Dim addEmp = New FbCommand("INSERT INTO CARDHOLDER (PHOTO) Values(@Photo) where cardholderid = 0002", myConnection)
                    addEmp.Parameters.Add("@Photo", FbDbType.Binary, photo.Length).Value = photo
                    myConnection.Open()
                    addEmp.ExecuteNonQuery()
                    Console.ForegroundColor = ConsoleColor.Green
                    Console.WriteLine(vbTab & myReader.Item(0) & vbTab & myReader.Item(2))
                    '  Console.WriteLine(photo)
                    myConnection.Close()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.