我有了一个时间的黑板,可以找到一部能够做到这一点的法典。 我只想到的是,通过使用该法典把照片储存成一种lob(也许不正确)。
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)
但是,在使用以下代码检索图像箱时:
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()
我在所述地区发现错误“参数无效”。 FYI 如果任何人甚至拥有比我能够pl倒和bu弄这些同样伟大的东西的更好的(工作)密码例子。