Insert Image in Mysql Blob Using Odbc

Last Reply 7 days ago By dharmendr

Posted 7 days ago

i have this code but not working. image in not saving in mysql database. my platform is .net framework 3.5 so unalbe to use


 Public Function insertimage(ByRef id As String)
        'ExecuteSQL("Delete from TempImage")
        Dim MyPathToImageFile As String
        If My.Computer.FileSystem.FileExists("\\Main\Radix\SRS\student-images\" & id & ".jpg") Then
            MyPathToImageFile = "\\Main\Radix\SRS\student-images\" & id & ".jpg"
            MyPathToImageFile = "\\Main\Radix\SRS\No Photo.jpg"
        End If
            Dim o As System.IO.FileStream
            Dim r As StreamReader
            Dim jpgFile As String = MyPathToImageFile
            o = New FileStream(jpgFile, FileMode.Open, FileAccess.Read, FileShare.Read)
            r = New StreamReader(o)
            Dim FileByteArray(o.Length - 1) As Byte
            o.Read(FileByteArray, 0, o.Length)
            Dim Con As New OdbcConnection(connString)
            Dim Sql As String = "Insert Into TempRecPhoto (Stud_Image,Studentid) Values((?)," & id & ")"
            Dim CmdObj As New OdbcCommand(Sql, Con)
            CmdObj.Parameters.Add("@Image", System.Data.OleDb.OleDbType.Binary, o.Length).Value = FileByteArray
        Catch ex As Exception
            '   MsgBox(ex.Message)
        End Try
    End Function


You are viewing reply posted by: dharmendr 7 days ago.