Insert blob

jhornnes

New member
Joined
Dec 20, 2005
Messages
3
Programming Experience
1-3
Hey.

  • Im using a mysql 4.0.X database, so that is clear
    (it dont support stored procedures etc)
  • Im using the myodbc connector to connect.

What im trying to do is insert some binary information into a blob field on the
mysql db by using a ordinary INSERT query. (no im not putting it into a
dataset/table and then insert that.

Im having a bit trouble doing this. Either the data becomes corrupt or the
filesize just gets out of hand (the inserted filesize becomes to big for the
blob although the file is "small")

How do i do this?
 
Im now using the native connector.. :)
But! The data is still corrupt. Works on BMP files, but jpeg, exe, et al doesnt work :(

VB.NET:
Private Function getFile(ByVal filepath As String) As Byte()
        
        Dim fs As New FileStream(filepath, FileMode.Open, FileAccess.Read)

        Dim br As BinaryReader = New BinaryReader(fs)
        Dim fi As New FileInfo(filepath)
        Dim file(fi.Length - 1) As Byte
        br.Read(file, 0, fi.Length)

        br.Close()
        fs.Close()

        Return file

    End Function


    Private Sub upload(ByVal file As String, ByVal Filename As String)

        Try
            Dim fil As Byte()
            fil = getFile(file)

            Dim conn As String = "server=;database=;uid=root;pwd=;old syntax=yes"
            Dim sql_conn As MySqlConnection = New MySqlConnection(conn)

     
            sql_conn.Open()


            Dim sql As String = "INSERT INTO filtest(Fil, Filnavn) VALUES(@Fil,@Filnavn )"
            Dim sql_cmd As MySqlCommand = New MySqlCommand(sql)
            sql_cmd.CommandType = CommandType.Text


            sql_cmd.Connection = sql_conn
            sql_cmd.Prepare()

            sql_cmd.Parameters.Add("@Fil", MySqlDbType.Blob, fil.Length).Value = fil
            sql_cmd.Parameters.Add("@Filnavn", MySqlDbType.String, Filename.Length).Value = Filename

            sql_cmd.ExecuteNonQuery()
            sql_conn.Close()

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub
 
Ive noticed that the actual problem is, that my blob files just has a max size of 65535 bytes. how can i store larger files?
 
Back
Top