Completing Your Own SQL Server Based Data Access Helper using COM+ and VB.NET - Retrieving a BLOB value from the database
(Page 6 of 6 )
The following method gives you an idea of how to retrieve BLOB values from the database:
Public Sub getBLOBValue(ByVal sqlSELECT As String, ByRef BinData() As Byte)
Dim Conn As SqlConnection
Dim cmd As SqlCommand
Dim ByteArray() As Byte
Try
Conn = New SqlConnection(_ConnectionString)
cmd = New SqlCommand(sqlSELECT, Conn)
Dim dr As SqlDataReader
With cmd
.Connection.Open()
dr = .ExecuteReader()
dr.Read()
ByteArray = dr.GetValue(0)
BinData = ByteArray
dr.Close()
.Connection.Close()
.Dispose()
End With
Catch ex As Exception
Try
If cmd.Connection.State = ConnectionState.Open Then
cmd.Connection.Close()
cmd.Dispose()
End If
Catch e As Exception
'do nothing...if still error persists
End Try
Throw New Exception(ex.Message & ". SQL Statement: " & sqlSELECT)
End Try
End Sub
Please note that I used the “ByRef” in the above method to send back the BLOB data.
Any feedback, suggestions, bugs, errors, improvements etc., are highly appreciated at jag_chat@yahoo.com.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |