Jump to content
Xtreme .Net Talk

Unable to cast object of type 'System.String' to type 'System.Byte[]'


Recommended Posts

Posted

Pls. help me with this error...

 

'Read the contents in to a byte array

Dim objMyData() As Byte

objMyData = CType(objMyRow("Document"), Byte()) <<<<<<<ERROR

 

Dim objMyFile As New FileStream("C:\temp\document.doc", FileMode.OpenOrCreate, FileAccess.Write)

objMyFile.Write(objMyData, 0, objMyData.Length)

 

 

Unable to cast object of type 'System.String' to type 'System.Byte[]' in vb.net

 

WHERE Document is a column in table in sql2005 that has a varchar(max) dataype.

 

I've tried converting it to

'Dim encoding As New System.Text.ASCIIEncoding()

'objMyData = encoding.GetBytes(objMyRow("Document"))

 

but the resulting document has an ascii format.

 

Thank you in advance....

  • Administrators
Posted

There are other encoding classes under System.Text you could use, System.Text.UnicodeEncoding or one of the System.Text.UTFxxEncoding classes instead.

 

Alternatively you might try using a StreamWriter to write the strings directly to the file rather than handling the encoding yourself.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...