How to fetch a file image from SQL using CSLA safedatareader

How to fetch a file image from SQL using CSLA safedatareader

Old forum URL: forums.lhotka.net/forums/t/4018.aspx


yimiqi posted on Monday, December 10, 2007

I have a file stored in a SQL table as type Image (= ByteArray). 

My DataPortal_Fetch looks like this:

Private Overloads Sub DataPortal_Fetch(ByVal crit As GetFileCriteria)

'call stored procedure

dr.Read()

FetchImage(dr)

dr.Close()

dr.Dispose()

End Sub

My SafeDataReader  procedure:

Private Sub FetchImage(ByVal dr As SafeDataReader)

' Value properties

m_FileImage = dr.GetBytes("FileImage")

End Sub

m_FileImage is declare as byte()

I can't get the SafeDataReader's GetBytes to work. Is it the right command to call to get an image data type from the database?

Thanks in advance. 

 

JoeFallon1 replied on Monday, December 10, 2007

I use code like this:

 Protected mImagefile As Byte() = Nothing

 Public Overridable Property Imagefile() As Byte()
      Get
        Return mImagefile
      End Get

      Set(ByVal Value As Byte())
        mImagefile = Value
      End Set
    End Property

     With dr
        If .Read Then
          mImagefile = CType(.Item("imagefile"), Byte())
        End If
      End With

Joe

yimiqi replied on Monday, December 10, 2007

Thanks for your code Joe, it works!

Copyright (c) Marimer LLC