Thread: MySql Blobs

  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Rep Power

    MySql Blobs

    Hi there

    Im trying to Insert a Microsoft Word Doc in to my MySql Database

    Dim cmd As New MySqlCommand         
    Dim SQL As String         
    Dim FileSize As UInt32         
    Dim rawData() As Byte         
    Dim fs As FileStream         
                 fs = New FileStream("c:\cright\MJTinvoice.doc", FileMode.Open, FileAccess.Read)
                 FileSize = fs.Length
                 rawData = New Byte(FileSize) {}
                 fs.Read(rawData, 0, FileSize)
                  SQL = "INSERT INTO Documents (Document) VALUES(?FileName)"
                 cmd.Connection = Conn
                 cmd.CommandText = SQL
                 cmd.Parameters.AddWithValue("?FileName", rawData)
                 MessageBox.Show("File Inserted into database successfully!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
             Catch ex As Exception
                 MessageBox.Show("There was an error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
             End Try
           End Sub
    this is the code that im trying to use. it appears to upload fine but when i try to download it, it come back corrupt.

    can anyone see where im going wrong. Is what om trying to do even possible.

    I have managed to do this successfully in the workbench application but never in VB

  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Rep Power
    I think there is an article here at devshed about storing blob's in mysql. I've never done it in VB either, but in general I believe you need to get the binary data into the db and also store the mime type, and then set the mime type when you retrieve the blob.
    Doug G
    I've never been able to appreciate the sublime arrogance of folks who feel they were put on earth just to save other folks from themselves .." - Donald Hamilton

IMN logo majestic logo threadwatch logo seochat tools logo