Introduction
To work with complex data, we generally use a dataset. We will create a web
service and use a dataset in the web service application that returns records from a student table.
There is a database "STUDENT" and a database table "student_detail".
So, let's create a web service.
Create an ASP.NET Web Service Application and replace the code with the following code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Data;
namespace WebService2
{
///
<summary>
///
Summary description for Service1
///
</summary>
[WebService(Namespace =
"http://tempuri.org/")]
[WebServiceBinding(ConformsTo =
WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called
from script, using ASP.NET AJAX, uncomment the following line.
//
[System.Web.Script.Services.ScriptService]
public
class Service1 : System.Web.Services.WebService
{
string connstring =
"Database=STUDENT;server=.;user=XXXX;password=XXXXXXXX";
DataSet ds;
DataView dv;
SqlDataAdapter da;
[WebMethod(Description=
"to show record")]
public
DataSet show()
{
da = new
SqlDataAdapter("select
* from STUDENT_DETAIL", connstring);
ds = new
DataSet();
da.Fill(ds);
return ds;
}
}
}
Run the service application.
Output:

Now we perform some more operatiosn. Now, I am creating a web service application
which can search the records and filter the records in a different way.
Again createa Web Service Application and replace the code with the following code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Data;
namespace WebService2
{
///
<summary>
///
Summary description for Service1
///
</summary>
[WebService(Namespace =
"http://tempuri.org/")]
[WebServiceBinding(ConformsTo =
WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called
from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public
class Service1 : System.Web.Services.WebService
{
string connstring =
"Database=STUDENT;server=.;user=XXXX;password=XXXXXXXX";
DataSet ds;
DataView dv;
SqlDataAdapter da;
[WebMethod(Description=
"to show record")]
public
DataSet show()
{
da = new
SqlDataAdapter("select
* from STUDENT_DETAIL", connstring);
ds = new
DataSet();
da.Fill(ds);
return ds;
}
[WebMethod(Description =
"simple filter")]
public
DataTable filter(string column)
{
da = new
SqlDataAdapter("select
* from STUDENT_DETAIL", connstring);
DataSet ds =
new DataSet();
da.Fill(ds);
DataView dv =
new DataView(ds.Tables[0]);
dv.RowFilter = "f_name like '"+column+"%'
";
return dv.ToTable();
}
[WebMethod(Description =
"advance sort")]
public
DataTable advancesort(string column,
string sort)
{
da = new
SqlDataAdapter("select
* from STUDENT_DETAIL", connstring);
DataSet ds =
new DataSet();
da.Fill(ds);
DataView dv =
new DataView(ds.Tables[0]);
dv.Sort = " "+column+"
" + ""+sort+"";
return dv.ToTable();
}
[WebMethod(Description =
"advancefilter")]
public
DataTable advancefilter(string column,
string value)
{
da = new
SqlDataAdapter("select
* from STUDENT_DETAIL", connstring);
DataSet ds =
new DataSet();
da.Fill(ds);
DataView dv =
new DataView(ds.Tables[0]);
dv.RowFilter = " "+column+"
= '" + value + "' ";
return dv.ToTable();
}
[WebMethod(Description="simple
sorting")]
public
DataTable sort(string column)
{
da = new
SqlDataAdapter("select
* from STUDENT_DETAIL", connstring);
DataSet ds =
new DataSet();
da.Fill(ds);
DataView dv =
new DataView(ds.Tables[0]);
dv.Sort = " "+ column +" ";
return dv.ToTable();
}
}
}
Create a web application and consume the service. Arrange the UI
controls the same as the below figure on the design page.

1 Comment
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.






Tejaswini PatilPosted May 3, 2014, 1:58 AM
Suppose web service return dataset which contain 100 parameter i want to filter these 100 parameter in web service and only select 10 among 100 and return result in xml format.is there possible to store dataset in web service side if yes then how?plz help me thank u..