Conversion error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CoolBreeze812
    New Member
    • May 2007
    • 3

    #1

    Conversion error

    Hi,

    Could some one help me with a conversion error I'm receiving. I'm trying to get the weather using webserviceX.net and I get the following error when I try to compile. By the way this is a ASP.NET 2.0 app.

    Cannot implicitly convert type 'net.webservice x.www.WeatherData[]' to 'net.webservice x.www.WeatherDa ta'

    Here is the code I'm using.
    [code=c]
    net.webservicex .www.WeatherFor ecast forcast = new net.webservicex .www.WeatherFor ecast();
    net.webservicex .www.WeatherFor ecasts forcasts = new net.webservicex .www.WeatherFor ecasts();
    net.webservicex .www.WeatherDat a data = new net.webservicex .www.WeatherDat a();

    forcasts = forcast.GetWeat herByZipCode("0 7747");
    data = forcasts.Detail s;

    TextBox1.Text = data.ToString() ;
    [/code]
    I would greatly appreciate it if someone could please help me resolve this.

    Thank you.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by CoolBreeze812
    Hi,

    Could some one help me with a conversion error I'm receiving. I'm trying to get the weather using webserviceX.net and I get the following error when I try to compile. By the way this is a ASP.NET 2.0 app.

    Cannot implicitly convert type 'net.webservice x.www.WeatherData[]' to 'net.webservice x.www.WeatherDa ta'

    Here is the code I'm using.
    [code=c]
    net.webservicex .www.WeatherFor ecast forcast = new net.webservicex .www.WeatherFor ecast();
    net.webservicex .www.WeatherFor ecasts forcasts = new net.webservicex .www.WeatherFor ecasts();
    net.webservicex .www.WeatherDat a data = new net.webservicex .www.WeatherDat a();

    forcasts = forcast.GetWeat herByZipCode("0 7747");
    data = forcasts.Detail s;

    TextBox1.Text = data.ToString() ;
    [/code]
    I would greatly appreciate it if someone could please help me resolve this.

    Thank you.
    (Please use the code tags)

    Line 1 you are creating a variable (forcasts) to hold a single forcast.
    You need to declare forcasts as an array instead so that you can retrieve the array of forcasts returned by the GetWeatherByZip Code function on Line 5.


    -Frinny

    Comment

    • CoolBreeze812
      New Member
      • May 2007
      • 3

      #3
      Originally posted by Frinavale
      (Please use the code tags)

      Line 1 you are creating a variable (forcasts) to hold a single forcast.
      You need to declare forcasts as an array instead so that you can retrieve the array of forcasts returned by the GetWeatherByZip Code function on Line 5.


      -Frinny
      Thanks for the reply and sorry about the code I realized it after I had already clicked submit.

      Can you please provide an example. If I make forcasts an array I won't be able to access the web method 'Details'.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by CoolBreeze812
        Thanks for the reply and sorry about the code I realized it after I had already clicked submit.

        Can you please provide an example. If I make forcasts an array I won't be able to access the web method 'Details'.
        First you make forcasts an array that holds a bunch of forcast information objects.
        Then when you want to access a specific forcast you'll do something like:
        [code=c]
        net.webservicex .www.WeatherFor ecast forcast = new net.webservicex .www.WeatherFor ecast();
        net.webservicex .www.WeatherFor ecast forcasts[] = forcast.GetWeat herByZipCode("0 7747");
        int i;
        for(i=0;i<forca sts.length;i++)
        {
        TextBox1.Text = TextBox1.Text +" "+ forcasts[i].Details;
        }
        [/code]
        (Please note that I usually work in VB.NET so this code may not work)

        -Frinny

        Comment

        Working...