title: how to populate list from sql server database in asp.net using json and ajax
body: <p>i want to populate a list from database i am using jquery mobile , asp.net, C#, and sql server database </p>
  
  <p>i wrote a service to get the data from the database as a dtataset but i couldn't convert the dataset to something json can understand </p>
  
  <p>so this is my service </p>
  
  <pre><code>[System.Web.Services.WebMethod]
      public static DataSet GetProducts()
      {
          string query = "SELECT [product] ,[img1] ,[descr] FROM [ELQ].[dbo].[products]";
          SqlCommand cmd = new SqlCommand(query);
  
          return GetData(cmd);
  
      }
      private static DataSet GetData(SqlCommand cmd)
      {
          string connString = "Data Source=GHOST-PC\\STC;Initial Catalog=ELQ_z;Integrated Security=True";
          using (SqlConnection con = new SqlConnection(connString))
          {
              using (SqlDataAdapter sda = new SqlDataAdapter())
              {
                  cmd.Connection = con;
                  sda.SelectCommand = cmd;
                  using (DataSet ds = new DataSet())
                  {
                      sda.Fill(ds);
                      return ds;
                  }
              }
          }
      } 
  </code></pre>
  
  <p>and this is my list </p>
  
  <pre><code> &lt;ul data-role="listview" data-inset="true" data-filter="true"&gt;
                  &lt;li&gt;&lt;a href="ray.html"&gt;
                      &lt;img src="pic/ip5.jpg"&gt;
                      Iphone &lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="scott.html"&gt;
                      &lt;img src="pic/s2.jpg"&gt;
                      S2&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="todd.html"&gt;
                      &lt;img src="pic/s3.jpg"&gt;
                      S3&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="dave.html"&gt;
                      &lt;img src="pic/nt2.jpg"&gt;
                      note2&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
  </code></pre>
  
  <p>how can i convert this to json and populate the list with ajax </p>