Hi SajidHussa,
Refer below example.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
HTML
<div id="dvDetails"></div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$.ajax({
type: "POST",
url: "Default.aspx/GetCustomers",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var xmlDoc = $.parseXML(response.d);
var xml = $(xmlDoc);
var customers = xml.find("Customers");
var employees = xml.find("Employees");
var rs = "";
if (employees.length > 0) {
rs += ' <div class="flavour"><h4 class="clrgray">Flavour</h4><div class="flavourcontainer">';
for (var i = 0; i < employees.length; i++) {
rs += '<a href="#" class="flavourtag">' + $(employees[i]).find('FirstName').text() + '</a>';
}
rs += '</div></div>';
}
$('#dvDetails').html(rs);
},
failure: function (response) {
alert(response.responseText);
},
error: function (response) {
alert(response.responseText);
}
});
});
</script>
Namespaces
C#
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Services;
VB.Net
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Web.Services
Code
C#
[WebMethod]
public static string GetCustomers()
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT TOP 10 CustomerID,ContactName FROM Customers GO SELECT EmployeeID,FirstName FROM Employees"))
{
cmd.Connection = con;
DataSet ds = new DataSet();
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.Fill(ds);
ds.Tables[0].TableName = "Customers";
ds.Tables[1].TableName = "Employees";
}
return ds.GetXml();
}
}
}
VB.Net
<WebMethod()>
Public Shared Function GetCustomers() As String
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand("SELECT TOP 10 CustomerID,ContactName FROM Customers GO SELECT EmployeeID,FirstName FROM Employees")
cmd.Connection = con
Dim ds As New DataSet()
Using sda As New SqlDataAdapter(cmd)
sda.Fill(ds)
ds.Tables(0).TableName = "Customers"
ds.Tables(1).TableName = "Employees"
End Using
Return ds.GetXml()
End Using
End Using
End Function