Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Error: Value of type 'Byte' cannot be converted to '1-dimensional array of Byte'

Error: Value of type 'Byte' cannot be converted to '1-dimensional array of Byte'

Scheduled Pinned Locked Moved ASP.NET
csharpdatabasegraphicssysadmin
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Milind Panchal
    wrote on last edited by
    #1

    Hi, I am Retrieving the binary image from sql database on web page. For that I have written following code in vb.net Dim stream As MemoryStream = New MemoryStream() Dim image As Byte() Dim bitmap As Bitmap Dim username As String username = Session("memberuser") con = New SqlConnection("server=ABC-0A55D6C3C90;database=satphere;uid=sa;pwd=") Try con.Open() cmd = New SqlCommand("select photo from ViewProfile where userid = @userid", con) cmd.Parameters.AddWithValue("@userid", username) >>>>>>>>> image = CByte(cmd.ExecuteScalar()) stream.Write(image, 0, image.Length) bitmap = New Bitmap(stream) Response.ContentType = "image/gif" 'bitmap.Save(Response.OutputStream, ImageFormat.Gif) bitmap.Save(Server.MapPath("TempImage/aa.gif")) Image1.ImageUrl = "TempImage/aa.gif" Catch ex As Exception con.Close() Stream.Close() End Try I am getting the error as Value of type 'Byte' cannot be converted to '1-dimensional array of Byte' line is mentioned by >>>>>> C#.net code for same is working fine--------------as follwos MemoryStream stream = new MemoryStream (); SqlConnection connection = new SqlConnection(@"server=ABC-0A55D6C3C90;database=Test;uid=sa;pwd="); try { connection.Open (); SqlCommand command = new SqlCommand("select Picture from Image", connection); byte[] image = (byte[])command.ExecuteScalar(); stream.Write(image, 0, image.Length); Bitmap bitmap = new Bitmap(stream); Response.ContentType = "image/gif"; bitmap.Save(Response.OutputStream, ImageFormat.Gif); //bitmap.Save(Server.MapPath("TempImage/aa.gif")); } finally { connection.Close (); stream.Close (); } can any one give me solution for this Thanks to all

    I L 2 Replies Last reply
    0
    • M Milind Panchal

      Hi, I am Retrieving the binary image from sql database on web page. For that I have written following code in vb.net Dim stream As MemoryStream = New MemoryStream() Dim image As Byte() Dim bitmap As Bitmap Dim username As String username = Session("memberuser") con = New SqlConnection("server=ABC-0A55D6C3C90;database=satphere;uid=sa;pwd=") Try con.Open() cmd = New SqlCommand("select photo from ViewProfile where userid = @userid", con) cmd.Parameters.AddWithValue("@userid", username) >>>>>>>>> image = CByte(cmd.ExecuteScalar()) stream.Write(image, 0, image.Length) bitmap = New Bitmap(stream) Response.ContentType = "image/gif" 'bitmap.Save(Response.OutputStream, ImageFormat.Gif) bitmap.Save(Server.MapPath("TempImage/aa.gif")) Image1.ImageUrl = "TempImage/aa.gif" Catch ex As Exception con.Close() Stream.Close() End Try I am getting the error as Value of type 'Byte' cannot be converted to '1-dimensional array of Byte' line is mentioned by >>>>>> C#.net code for same is working fine--------------as follwos MemoryStream stream = new MemoryStream (); SqlConnection connection = new SqlConnection(@"server=ABC-0A55D6C3C90;database=Test;uid=sa;pwd="); try { connection.Open (); SqlCommand command = new SqlCommand("select Picture from Image", connection); byte[] image = (byte[])command.ExecuteScalar(); stream.Write(image, 0, image.Length); Bitmap bitmap = new Bitmap(stream); Response.ContentType = "image/gif"; bitmap.Save(Response.OutputStream, ImageFormat.Gif); //bitmap.Save(Server.MapPath("TempImage/aa.gif")); } finally { connection.Close (); stream.Close (); } can any one give me solution for this Thanks to all

      I Offline
      I Offline
      Imran Khan Pathan
      wrote on last edited by
      #2

      try this code image = CType(cmd.ExecuteScalar(),Byte()) Best Regard Pathan

      ---------------------------------------------------

      1 Reply Last reply
      0
      • M Milind Panchal

        Hi, I am Retrieving the binary image from sql database on web page. For that I have written following code in vb.net Dim stream As MemoryStream = New MemoryStream() Dim image As Byte() Dim bitmap As Bitmap Dim username As String username = Session("memberuser") con = New SqlConnection("server=ABC-0A55D6C3C90;database=satphere;uid=sa;pwd=") Try con.Open() cmd = New SqlCommand("select photo from ViewProfile where userid = @userid", con) cmd.Parameters.AddWithValue("@userid", username) >>>>>>>>> image = CByte(cmd.ExecuteScalar()) stream.Write(image, 0, image.Length) bitmap = New Bitmap(stream) Response.ContentType = "image/gif" 'bitmap.Save(Response.OutputStream, ImageFormat.Gif) bitmap.Save(Server.MapPath("TempImage/aa.gif")) Image1.ImageUrl = "TempImage/aa.gif" Catch ex As Exception con.Close() Stream.Close() End Try I am getting the error as Value of type 'Byte' cannot be converted to '1-dimensional array of Byte' line is mentioned by >>>>>> C#.net code for same is working fine--------------as follwos MemoryStream stream = new MemoryStream (); SqlConnection connection = new SqlConnection(@"server=ABC-0A55D6C3C90;database=Test;uid=sa;pwd="); try { connection.Open (); SqlCommand command = new SqlCommand("select Picture from Image", connection); byte[] image = (byte[])command.ExecuteScalar(); stream.Write(image, 0, image.Length); Bitmap bitmap = new Bitmap(stream); Response.ContentType = "image/gif"; bitmap.Save(Response.OutputStream, ImageFormat.Gif); //bitmap.Save(Server.MapPath("TempImage/aa.gif")); } finally { connection.Close (); stream.Close (); } can any one give me solution for this Thanks to all

        L Offline
        L Offline
        l0kke
        wrote on last edited by
        #3

        My knowledge of VB is rubbish, but I would say the problem is as follows: cmd.ExecuteScalar() returns object, which is supposed to be array of bytes, but your call CByte(cmd.ExecuteScalar()) is trying to convert this object into object of type byte (not array of bytes) and that causes your error. Unfortunately, I don't know correct syntax in VB for casting object into array, I hope you do (otherwise you have to google it :)) Pilo

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups