Hallo
ich habe den Code von http://msdn2.microsoft.com/de-de/library/87z0hy49(VS.80).aspx für meine Zwecke abgewandelt, um einen BLOB-Typ aus unserer Oracle-DB ziehen zu können.
aber der Code funktioniert nicht ganz...
Dim oConn As New OdbcConnection( _
"DSN=ZDB;Uid=adhrabgleich;Pwd=rzmabgleich")
Dim cmd As New OdbcCommand
oConn.Open()
cmd.Connection = oConn
cmd.CommandText = "SELECT id, datei FROM dateien WHERE id = (SELECT MAX(" & _
"id) FROM dateien)"
Dim fs As FileStream ' Writes the BLOB to a file (
' *.bmp).
Dim bw As BinaryWriter ' Streams the binary data to the
' FileStream object.
Dim bufferSize As Integer = 100 ' The size of the BLOB buffer.
Dim outbyte(bufferSize - 1) As Byte ' The BLOB byte() buffer to be
' filled by GetBytes.
Dim retval As Long ' The bytes returned from GetBytes.
Dim startIndex As Long = 0 ' The starting position in the
' BLOB output.
Dim id As String = "" ' The publisher id to use in the file
' name.
Dim myReader As OdbcDataReader = cmd.ExecuteReader( _
CommandBehavior.SequentialAccess)
Do While myReader.Read()
' Get the publisher id, which must occur before getting the logo.
id = myReader.GetString(0)
' Create a file to hold the output.
fs = New FileStream("test.exe", FileMode.OpenOrCreate, _
FileAccess.Write)
bw = New BinaryWriter(fs)
' Reset the starting byte for a new BLOB.
startIndex = 0
' Read bytes into outbyte() and retain the number of bytes returned.
retval = myReader.GetBytes(1, startIndex, outbyte, 0, bufferSize)
' Continue reading and writing while there are bytes beyond the
' size of the buffer.
Do While retval = bufferSize
bw.Write(outbyte)
bw.Flush()
' Reposition the start index to the end of the last buffer and
' fill the buffer.
startIndex += bufferSize
retval = myReader.GetBytes(1, startIndex, outbyte, 0, _
bufferSize)
Loop
' Write the remaining buffer.
bw.Write(outbyte, 0, retval - 1)
bw.Flush()
' Close the output file.
bw.Close()
fs.Close()
Loop
' Close the reader and the connection.
myReader.Close()
oConn.Close() die ID kann ich auslesen, aber...
retval = myReader.GetBytes(1, startIndex, outbyte, 0, bufferSize) liefert mir nichts zurück...
WARUM???
kennt ihr eine Lösung?
Danke im Vorraus |