Fill Dataset from WebService in

The following code snippet demonstrate how we can use web method to fill the dataset in

1. Web Service Code: Write the FillGrid() function in your webservice.

    public XmlDocument FillGrid()
        string con = System.Configuration.ConfigurationManager.ConnectionStrings["localcon"].ConnectionString;
        SqlConnection cn = new SqlConnection(con);
        DataSet ds = new DataSet();
        string query = "select top 10 * from Person.Address";
        SqlDataAdapter da = new SqlDataAdapter(query, cn);
        XmlDocument mydata = new XmlDocument();
        return mydata;

2. Include web reference to your web site.

3. Use the following code in Page Load of your aspx code file.

        XmlDocument MyDoc = new XmlDocument();
        TestService.Service ob = new Service();
        System.Xml.XmlNode neNaode = ob.FillGrid();
        byte[] buf = System.Text.ASCIIEncoding.ASCII.GetBytes(neNaode.OuterXml);
        System.IO.MemoryStream ms = new MemoryStream(buf);
        DataSet myset = new DataSet();

from the above myset is the output dataset with the records.