title: Retrieving data from a database through SqlDataReader and converting it to JSON
body: <p>I want to convert my retrieved data into <code>JSON</code>; I am using a <code>SqlDataReader</code> for retrieving. For that I need to store my data into <code>var</code>.
  I am getting this error:</p>
  <blockquote>
  <p>An exception of type 'System.Reflection.AmbiguousMatchException' occurred in mscorlib.dll but was not handled in user code</p>
  <p>Additional information: Ambiguous match found.</p>
  </blockquote>
  <p>in the following code:</p>
  <pre><code>public string GetDetails(int Id)
  {   
      var jsonDoc = &quot;&quot;;
  
      string con = &quot;server=FACULTY01\\SQLSERVER2012ENT; database=SampleDb; uid=sa; pwd=sa9&quot;;
      SqlConnection scon = new SqlConnection(con);
      string qry = &quot;Select * from Information where ID =&quot; + Id;
      SqlCommand cmd = new SqlCommand(qry, scon);
      scon.Open();
      SqlDataReader rdr = cmd.ExecuteReader();
      var details = rdr;
      
      JavaScriptSerializer jss = new JavaScriptSerializer();
      jsonDoc = jss.Serialize(details);
      scon.Close();
      return jsonDoc;
  }
  </code></pre>