Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9027595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:46:58+00:00 2026-06-16T06:46:58+00:00

I want to create a service which fetch data from database and showing them

  • 0

I want to create a service which fetch data from database and showing them on a client page in a GridView, but i have problem that how i will manage the data coming from service through data table in Grid View
Plz help me out.

The following is my code:

Service Page with name “Service.svc”

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
sing System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Configuration;
[ServiceContract(Namespace = "myService")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service
{
   static private string sqlConString
   {
       get { return WebConfigurationManager.ConnectionStrings["SQLConnectionString"].ConnectionString; }
    }
    SqlConnection conn = new SqlConnection(sqlConString);

    [OperationContract]
    public DataTable FatchJobProporties()
    {
        conn.Open();
        try
        {
            string selQuery = "SELECT [job_title],[job_company],[job_vacancies],[job_description] FROM [dbo].[tb_job]";

         SqlCommand cmd = new SqlCommand(selQuery, conn);
         SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds, "tb_Job");
            DataTable dt = ds.Tables["tb_Job"];
            return dt;
        }
        catch (Exception ex)
        {
            throw ex;
        }

       finally
        {
            conn.Close();
            conn.Dispose();
        }
}

[DataContract]
public class JobProporties
{
    string jobTitle = "my";
    string jobCompany = "my";
    string jobDec = "my";
    int jobVacant = 0;

    [DataMember]
    public string JobTitle
   {
        get { return jobTitle; }
        set { jobTitle = value; }
    }

    [DataMember]
    public string JobCompany
    {
        get { return jobCompany; }
        set { jobCompany = value; }
    }

   [DataMember]
    public int JobVacant
    {
        get { return jobVacant; }
        set { jobVacant = value; }
    }

    [DataMember]
    public string JobDec
    {
        get { return jobDec; }
        set { jobDec = value; }
    }
}

This Service Receiving Page with name “default.aspx”

![<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

<script>

    function myFunc() {

        var proxy = new myService.Service();

        proxy.FatchJobProporties(onSuccess, onFail, null);


    }


    function onSuccess(result) {

        document.getElementById("tbDiv").innerHTML = result;

    }

    // This function is called if the service call fails

    function onFail() {

        alert("Fail to Fetch");
    }

</script>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <asp:ScriptManager ID="ScriptManager1" runat="server">

            <Services>

                <asp:ServiceReference Path="Service.svc" />

            </Services>

        </asp:ScriptManager>

        <input id="Button1" type="button" value="button" onclick="return myFunc();" />

        <div id="tbDiv">

        </div>


    </div>

    </form>

</body>

</html>][1]

Output:
whole data come in a single line;
for output see the image

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T06:46:59+00:00Added an answer on June 16, 2026 at 6:46 am

    Use the List class in return type to return multiple records.

    try this code.

    [DataContract]
    public class Customer
    {
        [DataMember]
        public int CustomerID{ get; set; }    }
    
        [DataMember]
        public string CustomerName{ get; set; }    
    }
    
    
    public interface ICustomerService
    {
    
       [OperationContract]
       List<Customer> GetAllCustomer();
    }
    
    
    public class CustomerService:ICustomerService
    {
    
       List<Customer> GetAllCustomer()
       {
           List<Customer> customers = new List<Customer>();
    
           using(SqlConnection con = new SqlConnection("Database Connection String"))
           {
            con.Open();     
            using(SqlCommand cmd = new SqlCommand("Select * from Customer",con))
            {
                SqlDataReader dr = cmd.ExecuteReader();
    
                while(dr.Read())
                {
                    Customer customer = new Customer();
                    customer.CustomerID =Parse.Int(dr[0].ToString());
                    customer.CustomerName =dr[1].ToString(); 
                    customers.Add(customer);
                }
            }
           }
        return customers;
      }
    }
    

    Enjoy!!!!

    Thanks
    Ck Nitin (TinTin)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a service which receives a request from the client, adds
I want to create a service which will insert provided data into spreadsheet fields
Hi I want to create a WCF service that have login method, which is
I want to create a web service in ASP.NET that fetches data from a
I have created a soap service which I want to test.But I dont want
I want to create windows service which recieves via some queue tasks to run
I want to create an iPhone app which makes calls to a web service.
I want to create WCF service and client. I want to add 2 way
I want to create new WCF service and client. The 2 parties will communicate
I have a windows service which is using a method from a class library

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.