title: Webservice to save data to Json format
body: <p>I am new to webservice in dot net and i am trying to save the data in Json format ,Below is the code of my service.asmx file, Here i am getting the data from the database, but i don't have the idea how to save the data in Json format. Pls guide me with a solution for this.</p>
  
  <pre><code>using System;
  using System.Collections;
  using System.ComponentModel;
  using System.Data;
  using System.Linq;
  using System.Web;
  using System.Web.Services;
  using System.Web.Services.Protocols;
  using System.Web.Script.Services;
  using System.Xml.Linq;
  using System.Collections.Generic;
  using System.Data.Sql;
  using System.Data.SqlClient;
  
  namespace JSONWeb
  {
      /// &lt;summary&gt;
      /// Summary description for Service1
      /// &lt;/summary&gt;
      [WebService(Namespace = "http://tempuri.org/")]
      [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
      [ToolboxItem(false)]
      [ScriptService]
  
      // 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
      {
          [WebMethod]
          public DataSet SelectData()
          {
              SqlConnection con = new SqlConnection("Data Source=HOME;database=Data;Integrated Security=true");
              SqlCommand cmd = null;
              SqlDataAdapter da;
              DataSet ds = new DataSet();
              try
              {
                  con.Open();
                  cmd = new SqlCommand("SelectData", con);
                  cmd.CommandType = CommandType.StoredProcedure;
                  da = new SqlDataAdapter(cmd);
                  da.Fill(ds);
              }
              catch (Exception ex)
              {
                  throw ex;
              }
              finally
              {
                  con.Close();
              }
              return ds;
          }
      }
  }
  </code></pre>