Click here to Skip to main content
15,035,283 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys

I am working on an application that would upload and save images to a database through web service. I am having an error, here's my code below. The error :
value of type 'string' cannot be converted to '1-dimensional array of byte'. The error is happening on (Textbox1.Text) highlighted below in bold.

Can you please help me to solve this problem.

VB
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ws As New localhost.Service1()
        Dim data() As Byte
        data = ws.ImageRetrieve(TextBox1.Text)
        Dim s As New FileStream(Server.MapPath(Request.ApplicationPath) & "\sample.jpg", FileMode.Create)
        s.Write(data, 0, data.Length)
        s.Close()
        Image1.ImageUrl = Server.MapPath(Request.ApplicationPath) & "\sample.jpg"

    End Sub
Posted
Updated 28-Mar-10 15:47pm
v2

You have not shown the webservice code. What does ImageRetrieve method take as a paramater? I'm guessing it isn't a string.
   
In your webservice declaration for ImageRetrieve, you must have written it as: Dim myText() As String when you should have written: Dim myText As String.
The difference is that parenthesis, which indicate that you want myText to be a String array (more than one value and therefore needing an index when assigning values).

Just take away the () on the myText definition in ImageRetrieve method and your issue should be resolved.
   
Thank you veru much Sandeep, your suggestion did the trick.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900