Sayed Faiz

Sayed Faiz

  • NA
  • 7
  • 0

How to Read Dataset row value from a Webservice

Apr 26 2009 6:19 AM
Hi...I need to consume a web service, which, when provided with State and Suburb, returns postcode.
The existing web service return DataSet, and produces the following XML.
<DataSet>
<xs:schema id="NewDataSet">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Postcode">
<xs:complexType>
<xs:sequence>
<xs:element name="Suburb" type="xs:string" minOccurs="0"/>
<xs:element name="Postcode" type="xs:string" minOccurs="0"/>
<xs:element name="State" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram>
<NewDataSet>

<Postcode diffgr:id="Postcode1" msdata:rowOrder="0">
<Suburb>NORTH PARRAMATTA</Suburb>
<Postcode>1750</Postcode>
<State>NSW</State>
</Postcode>

<Postcode diffgr:id="Postcode2" msdata:rowOrder="1">
<Suburb>NORTH PARRAMATTA</Suburb>
<Postcode>2151</Postcode>
<State>NSW</State>
</Postcode>

<Postcode diffgr:id="Postcode3" msdata:rowOrder="2">
<Suburb>PARRAMATTA</Suburb>
<Postcode>1740</Postcode>
<State>NSW</State>
</Postcode>

</NewDataSet>
</diffgr:diffgram>
</DataSet>

As it returns more than one row, I need to retirieve the Postcode value from the 1ST ROW only. I am using C# method to retrieve the Dataset value, but don't know how to do it.
My C# method in the code behind page to call the web service method is as below:
private DataSet GetPostcode(string txtSuburb, string txtState, string txtPostcode)
        {
                DataSet PostCodeSet = new DataSet();
                PostcodeService pcode = new PostcodeService();

                PostCodeSet = pcode.GetPostcodeAndSuburbForAustralia(txtSuburb, txtState, txtPostcode);     
            }
            return PostCodeSet;
        }

Here is what I have got in the Button_Click event of my Web Page:

DataSet PCodeSet = new DataSet();
PCodeSet = GetPostcode(StateList.SelectedValue.ToString(), HomeSuburbTextbox.Text.ToString(), null);
HomePostcodeLabel.Text = ??????????

So my question is how to populate the Label with the Postcode value from the 1st row. Any help would be really appreciated. Thanks.

Answers (1)