Stoing an image in mysql blob with VB2005

Hi i have the following code which displays the image in the picturebox and updates the text entries in the db but dousnt upload the picture to the db please help!
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        'Display Picture File
        On Error Resume Next
        OpenFileDialog1.InitialDirectory = "d:\pic"
        OpenFileDialog1.DefaultExt = "gif"
        OpenFileDialog1.Filter = "Bmp Files(*.bmp)|*.bmp|Gif Files(*.gif)|*.gif|Jpg Files(*.jpg)|*.jpg"
        OpenFileDialog1.ShowDialog()
        PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
        Dim theImage As Image
        Dim theStream As New MemoryStream
        Dim theBytes As Byte()
        Dim iCount As Integer


        theImage = Image.FromFile(OpenFileDialog1.FileName)
        theImage.Save(theStream, Imaging.ImageFormat.Jpeg)
        theBytes = New Byte(theStream.Length - 1) {}
        iCount = theStream.Read(theBytes, 0, theStream.Length - 1)


        Dim xExt As String
        Dim memorystream As System.IO.MemoryStream
        Dim ImageByte As Byte()
        ' Call OpenServer()
        Dim rs As ADODB.Recordset
        rs = New ADODB.Recordset()
        On Error Resume Next

        '  On Error GoTo SaveError
        rs.Open("select * from questions where id = '" & Label6.Text & "'", conn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockPessimistic, 1)
        rs.Update()
        rs.Fields("question").Value = TextBox2.Text
        rs.Fields("a1").Value = TextBox3.Text
        rs.Fields("a2").Value = TextBox4.Text
        rs.Fields("a3").Value = TextBox5.Text

        MsgBox("doing image")
        rs.Fields("file").Value = theBytes

        rs.Update()
        rs.Close()
        rs = Nothing

        Exit Sub
    End Sub
LVL 1
greenbug2002Asked:
Who is Participating?
 
DhaestCommented:
Try
        rs.Open("select * from questions where id = '" & Label6.Text & "'", conn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockPessimistic, 1)
        rs.Update()
        rs.Fields("question").Value = TextBox2.Text
        rs.Fields("a1").Value = TextBox3.Text
        rs.Fields("a2").Value = TextBox4.Text
        rs.Fields("a3").Value = TextBox5.Text

        MsgBox("doing image")
        rs.Fields("file").Value = theBytes

        rs.Update()
        rs.Close()
        rs = Nothing
catch exception ex
  messagebox.show (ex.tostring())
end try
0
 
DhaestCommented:
Do you get any error ?
0
 
greenbug2002Author Commented:
no it runs fine an if i look at the table with phpMyAdmin 6.5k of data is in the blob but
        Dim xExt As String
        Dim memorystream As System.IO.MemoryStream
        Dim ImageByte As Byte()

ImageByte = (rs.Fields("file").Value)
memorystream = New IO.MemoryStream(ImageByte)
PictureBox1.Image = Image.FromStream(memorystream)
memorystream.Close()

Douse not display the stored image in PictureBox1 so im gessing im ether putint the data in incorectly or reading it incorectly but im not getting eney errors attall when i run the code
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.