Public Sub DownloadBlob(ByVal myConnection As OracleConnection)
Dim myCommand As New OracleCommand("SELECT * FROM Pictures", myConnection)
myConnection.Open()
Dim myReader As OracleDataReader = myCommand.ExecuteReader(System.Data.CommandBehavior.Default)
Try
While myReader.Read()
Dim myLob As OracleLob = myReader.GetOracleLob(myReader.GetOrdinal("Picture"))
If Not myLob.IsNull Then
Dim FN As String = myReader.GetString(myReader.GetOrdinal("PicName"))
Dim fs As FileStream = New FileStream("D:\Tmp\" + FN + ".bmp", FileMode.Create)
Dim w As BinaryWriter = New BinaryWriter(fs)
w.Write(myLob.Value)
w.Close()
fs.Close()
Console.WriteLine(String.Concat(FN, " downloaded."))
End If
End While
Finally
myReader.Close()
myConnection.Close()
End Try
End Sub
Public Sub UploadBlob(ByVal myConnection As OracleConnection)
Dim fs As FileStream = New FileStream("D:\Tmp\_Water.bmp", FileMode.Open, FileAccess.Read)
Dim r As BinaryReader = New BinaryReader(fs)
myConnection.Open()
Dim myLob As OracleLob = New OracleLob(myConnection, OracleDbType.Blob)
Dim streamLength As Int32 = fs.Length
myLob.Write(r.ReadBytes(streamLength), 0, streamLength)
Dim myCommand As OracleCommand = New OracleCommand("INSERT INTO Pictures (ID, PicName, Picture) VALUES(1,'Water',:Pictures)", myConnection)
Dim myParam As OracleParameter = myCommand.Parameters.Add("Pictures", OracleDbType.Blob)
myParam.OracleValue = myLob
Try
Console.WriteLine(myCommand.ExecuteNonQuery() & " rows affected.")
Finally
myConnection.Close()
r.Close()
fs.Close()
End Try
End Sub