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

Last post 06-30-2009 6:12 AM by qwe123kids. 1 replies.

Sort Posts:

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

    06-30-2009, 5:02 AM

    hi 

    i am geting an error on the below code

    the follwoing error is

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

     

     

    theQuery.Connection.Open()

    theDataAdapter.Fill(theDataSet)

    theQuery.Connection.Close()

     Dim theQuery As New OleDbCommand("SELECT Images FROM tblImages", New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\Images.mdb;"))Dim theDataSet As New DataSet()Dim theDataAdapter As New OleDbDataAdapter(theQuery)'MsgBox(theDataSet.Tables(0).Rows.Item(0).Item(0))

     'get row

     Dim theItem As Object = theDataSet.Tables(0).Rows(0).Item(0)

    Dim correctObject() As Byte = CType(theItem, Byte()) Cry

    If correctObject Is Nothing = False Then 'read into memstream

     theMemStream.Write(correctObject, 0, correctObject.Length)

    theMemStream.Position = 0

     Using theMemStream As New MemoryStream()Me.PictureBox1.Image = Image.FromStream(theMemStream)End Using

     

    End If

    Work hard and become a leader; be lazy and never succeed. (Proverbs 12:24)
  • Re: Unable to cast object of type 'System.String' to type 'System.Byte[]'.

    06-30-2009, 6:12 AM
    Answer
    • All-Star
      21,007 point All-Star
    • qwe123kids
    • Member since 03-27-2008, 5:49 AM
    • Posts 3,602
    Hi,
    U may have Use ASCIIENCODING,,

    String MyString;

    System.Text.ASCIIEncoding ASCIIEncoding = New System.Text.ASCIIEncoding;
    MyString = ASCIIEncoding.GetString(Bytes);

    OR
    http://bytes.com/topic/net/answers/788635-unable-cast-object-type-system-byte-type-system-iconvertible
    Check the above Link
    Thanks
    Avinash Tiwari

    Remember to click “Mark as Answer” on the post, if it helps you.

    MY Blog

    Hacking Inside .net exe
Page 1 of 1 (2 items)