title: Writing Json string from SQL query in C#
body: <p>I want to create a json string inside "reader.Read()" how can I do that? This is for a API I'm creating so you can request the page for example api.ashx?tablename=CurrencySymbol&amp;id=5 Hope someone can help</p>
  
  <p>I would like to create json from column values from the database</p>
  
  <p>** Lets not worry about the security of this, it's just for a internal application that only I will use **</p>
  
  <pre><code>    public void ProcessRequest (HttpContext context) 
      { 
          context.Response.Clear();
  
              string tablename = context.Request.QueryString["tablename"];
              int ID = Int32.Parse(context.Request.QueryString["ID"]);
              context.Response.ContentType = "text/html";
  
              SqlConnection sqlConnection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["WorldViewDatabase"].ConnectionString);
              SqlCommand cmd = new SqlCommand();
              SqlDataReader reader;
  
              cmd.CommandText = "SELECT * FROM " + tablename "WHERE ID = " + ID;
              cmd.CommandType = CommandType.Text;
              cmd.Connection = sqlConnection1;
  
              sqlConnection1.Open();
  
              reader = cmd.ExecuteReader();
              // Data is accessible through the DataReader object here.
              while (reader.Read())
              {
                  //context.Response.Write(reader);
              }
              sqlConnection1.Close();
  
              context.Response.Write(ID);
              context.Response.Write(tablename);
              return;
     }
  </code></pre>