callraheel
Well-known member
Hello
Now the photo is not retrieving back...Its saves well and i have created some code which you can see as follows to get back photo :
Public Shared Function GetPictureFromDB(ByVal sid As String) As MemoryStream
' returning stream
Dim rStream As New MemoryStream
Try
Dim q As String = "SELECT PhotoSize,Photo FROM photos WHERE PhotoID='" & sid & "';"
Dim connDB As New MySqlConnection
connDB = Connection.AutoConnect
Dim objCmd As New MySqlCommand(q, connDB)
Dim objReader As MySqlDataReader
objReader = objCmd.ExecuteReader(CommandBehavior.SequentialAccess)
' create an array to return..
While objReader.Read()
' first get the size of the picture
Dim picSize As Long = objReader.Item("PhotoSize")
' specify the constant size of bytes to fetch
Const bufferSize As Integer = 200
Dim startIndex As Long = 0
Dim outByte(bufferSize - 1) As Byte
Dim gotBytes As Long
' now start reading and saving in the memory stram...
gotBytes = objReader.GetBytes(1, startIndex, outByte, 0, bufferSize)
' now using this picture size get all data from BLOB value of Photo
Do While bufferSize = gotBytes
' save the fetched byte array...
rStream.Write(outByte, 0, outByte.Length - 1)
' now increment the fetchedbyte
startIndex += bufferSize
' now proceed reading and saving in the memory stram...
gotBytes = objReader.GetBytes(1, startIndex, outByte, 0, bufferSize)
Loop
' save the fetched byte array...
rStream.Write(outByte, 0, outByte.Length - 1)
Console.WriteLine("Last Got Bytes : " & gotBytes)
End While
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Function
Now see it do well until the last fetch operation. Where it says the array cannot be null it means the last time the values are not written properly..So anyone can help out please..............
Regards
Now the photo is not retrieving back...Its saves well and i have created some code which you can see as follows to get back photo :
Public Shared Function GetPictureFromDB(ByVal sid As String) As MemoryStream
' returning stream
Dim rStream As New MemoryStream
Try
Dim q As String = "SELECT PhotoSize,Photo FROM photos WHERE PhotoID='" & sid & "';"
Dim connDB As New MySqlConnection
connDB = Connection.AutoConnect
Dim objCmd As New MySqlCommand(q, connDB)
Dim objReader As MySqlDataReader
objReader = objCmd.ExecuteReader(CommandBehavior.SequentialAccess)
' create an array to return..
While objReader.Read()
' first get the size of the picture
Dim picSize As Long = objReader.Item("PhotoSize")
' specify the constant size of bytes to fetch
Const bufferSize As Integer = 200
Dim startIndex As Long = 0
Dim outByte(bufferSize - 1) As Byte
Dim gotBytes As Long
' now start reading and saving in the memory stram...
gotBytes = objReader.GetBytes(1, startIndex, outByte, 0, bufferSize)
' now using this picture size get all data from BLOB value of Photo
Do While bufferSize = gotBytes
' save the fetched byte array...
rStream.Write(outByte, 0, outByte.Length - 1)
' now increment the fetchedbyte
startIndex += bufferSize
' now proceed reading and saving in the memory stram...
gotBytes = objReader.GetBytes(1, startIndex, outByte, 0, bufferSize)
Loop
' save the fetched byte array...
rStream.Write(outByte, 0, outByte.Length - 1)
Console.WriteLine("Last Got Bytes : " & gotBytes)
End While
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Function
Now see it do well until the last fetch operation. Where it says the array cannot be null it means the last time the values are not written properly..So anyone can help out please..............
Regards