Wednesday, 11 September 2013

Display an image on a Windows.Form from a SQL Database in VB 6

Display an image on a Windows.Form from a SQL Database in VB 6

I have some headshots in an ID Card database that I want to display in a
program I am writing in VB 2008. The following code is based off of a
support article from Microsoft, it can be found here and is specifically
from step '11'.
aiuQuery.CommandText = "select a.ImageData From Images a, Cardholders
b WHERE b.UserText6 = '" & _
empID & "' And a.CardholderID = b.CardholderID"
aiuReader = aiuQuery.ExecuteReader
If aiuReader.Read Then
Dim bytBLOBData(aiuReader.GetBytes(1, 0, Nothing, 0,
Integer.MaxValue) - 1) As Byte
aiuReader.GetBytes(1, 0, bytBLOBData, 0, bytBLOBData.Length)
Dim stmBLOBData As New MemoryStream(bytBLOBData)
pbHeadShot.Image = Image.FromStream(stmBLOBData)
End If
aiuReader.Close()
The first line inside the 'If' block (Dim bytBLOBData...) generates an
error claiming "Index was outside the bounds of the array."
The SQL is correct as tested outside of the program.
Any suggestions on what the cause of this error could be? A better way to
go about this?

No comments:

Post a Comment