title: How to return JSON object by executing SQL Server stored procedure
body: <p>I am using this method to return a <code>XML</code> as result. I need to return a json object after executing the stored procedure. Where should I edit the following code to return a JSON object?</p>
  
  <pre><code>public XmlElement GetGraphData(int eventTypeID, int patientID)
  {
      SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ToString());
      con.Open();
  
      SqlCommand cmd = new SqlCommand("sp_GetGraphData", con);
      cmd.CommandType = CommandType.StoredProcedure;
      cmd.Parameters.AddWithValue("@EventID", eventTypeID);
      cmd.Parameters.AddWithValue("@PatientID", patientID);
  
      cmd.ExecuteNonQuery();
  
      SqlDataAdapter da = new SqlDataAdapter(cmd);
  
      DataSet ds = new DataSet();
      da.Fill(ds);
  
      con.Close();
  
      XmlDataDocument xmldata = new XmlDataDocument(ds);
      XmlElement xmlElement = xmldata.DocumentElement;
  }
  </code></pre>