Can't Insert Large Files BLOB

Can't Insert Large Files BLOB

Postby duke_topmost » Mon 31 Oct 2005 11:45

Hi~ I am register user ,Use 3.05 for .NET Framework 1.X Version
This is my code .when the picture is small size whe be fine
but when picture size more 300K will have error
coule tell me how to do it ..
Dim FileSize As Long
Dim rawData() As Byte
Dim fs As FileStream
'fs = New FileStream(Application.StartupPath & "\ICON.png", FileMode.Open, FileAccess.Read)
fs = New FileStream("E:\Picture\100_2530.JPG", FileMode.Open, FileAccess.Read)

Dim r As BinaryReader = New BinaryReader(fs)
'Dim myBlob As MySqlBlob = New MySqlBlob(r.ReadBytes(Convert.ToInt32(fs.Length)))
Dim myBlob As MySqlBlob = New MySqlBlob(r.ReadBytes(Convert.ToInt64(fs.Length)))
str_SQL = "Update m_program set picture1 = :picture1 Where pkey= '" & Pkey & "'"
Dim Command As MySqlCommand = New MySqlCommand(str_SQL, myConnection)
Command.Parameters.Add("picture1", myBlob)
Posts: 3
Joined: Mon 31 Oct 2005 11:35

Postby Serious » Tue 01 Nov 2005 08:16

Do not use MySqlBlob in this case. It is better to use byte array instead. Here is sample code:
Code: Select all
      Dim buffer As Byte() = Nothing
      Using fs As FileStream = New FileStream("d:\1.bmp", FileMode.Open)
            buffer = New Byte(fs.Length  - 1) {}
            fs.Read(buffer, 0, buffer.Length)
      End Using
      Dim connection As New MySqlConnection("host=server;port=3307;database=test;user id=root;password=root;")
      Dim command As New MySqlCommand("update mysqlnet_pictures set picture = :picture where uid = :uid", connection)
      command.Parameters.Add("picture", buffer)
      command.Parameters.Add("uid", 1)
I tested this sample with 2.25 Mb picture and found no problems.
For more information please refer to 'Pictures' demo project.

Return to dotConnect for MySQL