[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 265
  • Last Modified:

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
0
greenbug2002
Asked:
greenbug2002
  • 2
1 Solution
 
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
 
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
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now