Note that there are some explanatory texts on larger screens.

plurals
  1. POVB.net - insert/retrieve picture from mysql Database directly to/from a Picturebox
    primarykey
    data
    text
    <p>I'm am having a heck of a time finding a code snippet that works for this. I have got to the point where it appears the picture is stored as a blob (perhaps incorrectly) by using this code.</p> <pre><code> Dim filename As String = txtName.Text + ".jpg" Dim FileSize As UInt32 Dim ImageStream As System.IO.MemoryStream ImageStream = New System.IO.MemoryStream PbPicture.Image.Save(ImageStream, System.Drawing.Imaging.ImageFormat.Jpeg) ReDim rawdata(CInt(ImageStream.Length - 1)) ImageStream.Position = 0 ImageStream.Read(rawdata, 0, CInt(ImageStream.Length)) FileSize = ImageStream.Length Dim query As String = ("insert into actors (actor_pic, filename, filesize) VALUES (?File, ?FileName, ?FileSize)") cmd = New MySqlCommand(query, conn) cmd.Parameters.AddWithValue("?FileName", filename) cmd.Parameters.AddWithValue("?FileSize", FileSize) cmd.Parameters.AddWithValue("?File", rawData) cmd.ExecuteNonQuery() MessageBox.Show("File Inserted into database successfully!", _ "Success!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk) </code></pre> <p>but on retieving to the picturebox using the following code:</p> <pre><code> Private Sub GetPicture() 'This retrieves the pictures from a mysql DB and buffers the rawdata into a memorystream Dim FileSize As UInt32 Dim rawData() As Byte Dim conn As New MySqlConnection(connStr) conn.Open() conn.ChangeDatabase("psdb") Dim cmd As New MySqlCommand("SELECT actor_pic, filesize, filename FROM actors WHERE actor_name = ?autoid", conn) Cmd.Parameters.AddWithValue("?autoid", Actor1Box.Text) Reader = cmd.ExecuteReader Reader.Read() 'data is in memory FileSize = Reader.GetUInt32(Reader.GetOrdinal("filesize")) rawData = New Byte(FileSize) {} 'get the bytes and filesize Reader.GetBytes(Reader.GetOrdinal("actor_pic"), 0, rawData, 0, FileSize) Dim ad As New System.IO.MemoryStream(100000) ' Dim bm As New Bitmap ad.Write(rawData, 0, FileSize) Dim im As Image = Image.FromStream(ad) * "error occurs here" (see below) Actor1Pic.Image = im Reader.Close() conn.Close() conn.Dispose() ad.Dispose() </code></pre> <p>I get the error "parameter not valid" in the area noted. FYI If anyone even has some better (working) code examples than this that I can plug in versus debugging this mess that would be great too.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload