Why does the ISingleResult return an array of bytes as a string?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ronald Ray
    New Member
    • Aug 2010
    • 2

    Why does the ISingleResult return an array of bytes as a string?

    I need the stored procedure to return the array of bytes instead of a string.

    The error I am getting is: Unable to cast object of type System.Byte[] to type System.String.

    Code:
            ISingleResult<spVTGetAttachmentSelectResult> Result = ava.GetAttachment(AttachmentID);
    
            foreach (spVTGetAttachmentSelectResult Pdf in Result)
            {
    
                System.Text.UTF8Encoding Str = new System.Text.UTF8Encoding();
          
                string FileName  = Pdf.Attachment;
           
                string Extension = (Pdf.FileExtension).ToString();
                            
                byte[] DocBuffer = Str.GetBytes(FileName);
    
            }
    The stored procedure:
    Code:
    ALTER PROCEDURE [dbo].[spVTGetAttachmentSelect] (@AttachmentID int)
    AS
    BEGIN
    
    	SELECT     VehicleAttachments.Attachment, VehicleAttachments.FileExtension
                   
    	FROM       VehicleAttachments
    	
    	WHERE     (VehicleAttachments.AttachmentID =  @AttachmentID)	
    	
    END
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Is spVTGetAttachme ntSelectResult a custom class somewhere?
    The problem could be with it.
    I've never used ISingleResult before so I'm not sure how it is supposed to behave.

    EDIT: Scratch that, is the error coming from this line:
    string FileName = Pdf.Attachment;

    Pdf.Attachment is probably already a byte[]

    Comment

    Working...