以下是我使用的代码,它插入一个BLOB,但下载后的图像为0KB。无法弄清楚如何正确阅读所有这些内容。
Dim temp As String = OpenFileDialog1.FileName
Dim FileStream As Stream = System.IO.File.OpenRead((temp))
Dim array() As Byte = File.ReadAllBytes(temp)
Using memory As MemoryStream = New MemoryStream(array)
Using reader As BinaryReader = New BinaryReader(memory)
STSQL = "insert into mpcs.image_resource"
STSQL = STSQL & " ("
STSQL = STSQL & "IMAGE_TYPE,"
STSQL = STSQL & "IMAGE_NAME,"
STSQL = STSQL & "IR_ID,"
STSQL = STSQL & "IMAGE,"
STSQL = STSQL & "APP_NAME,"
STSQL = STSQL & "SIZE_BYTES,"
STSQL = STSQL & "APP_NAME_TCAT"
STSQL = STSQL & ") values ("
STSQL = STSQL & "'image/jpg'," 'IMAGE_TYPE
STSQL = STSQL & "'" & Label40.Text & "'," 'IMAGE_NAME
STSQL = STSQL & "MPCS.IMAGE_RESOURCE_PK_SEQUENCE.NEXTVAL," 'IR_ID
STSQL = STSQL & "'" & reader.ReadByte & "'," 'IMAGE
STSQL = STSQL & "'SHOP_INV'," 'APP_NAME
STSQL = STSQL & "'" & FileStream.Length & "'," 'Size Bytes
STSQL = STSQL & "'IR_APP_NAME'" 'APP_NAME_TCAT
STSQL = STSQL & ")"
好的,这是我在学习了更多内容之后的最新尝试,我不知道这是否有效,但到目前为止,我在这个问题上得到了一个缺失的表达方式,而且我并没有这样做。知道它在哪里。
Dim fs As New System.IO.FileStream(OpenFileDialog1.FileName, IO.FileMode.Open, IO.FileAccess.Read)
Dim b(fs.Length() - 1) As Byte
fs.Read(b, 0, b.Length)
fs.Close()
Dim query As String = "INSERT INTO mpcs.image_resource (IMAGE, IMAGE_TYPE, IMAGE_NAME, SIZE_BYTES, IR_ID) VALUES (@IMAGE, @TYPE, @NAME, @SIZE, @IRID)"
Using Conn As New OleDbConnection(Private)
Using CMD As New OleDbCommand()
With CMD
.Connection = Conn
.CommandType = CommandType.Text
.CommandText = query
.Parameters.AddWithValue("@IMAGE", OleDbType.Binary).Value = b
.Parameters.AddWithValue("@TYPE", OleDbType.VarChar).Value = "image/jpg"
.Parameters.AddWithValue("@NAME", OleDbType.VarChar).Value = Label40.Text
.Parameters.AddWithValue("@SIZE", OleDbType.Numeric).Value = b.Length
.Parameters.AddWithValue("@IRID", OleDbType.Numeric).Value = "MPCS.IMAGE_RESOURCE_PK_SEQUENCE.NEXTVAL"
End With
Try
Conn.Open()
CMD.ExecuteNonQuery()
Catch ex As OleDbException
MessageBox.Show(ex.Message.ToString(), "Error Message")
End Try
End Using
End Using