title: using C# update SQL table from a JSON
body: <p>I am calling a web service that outputs a <code>JSON</code> payload, the <code>JSON</code> string has <em>productName</em>, <em>packageId</em>, <em>webReferenceId</em>. When calling the web service the <em>productName</em> is passed as the query string. I am able to pass the query string and retrieve the <code>JSON</code> payload that has <em>productName</em>, <em>packageId</em>, <em>webReferenceId</em> as shown below.</p>
  <p><em><strong>JSON:</strong></em></p>
  <pre><code>{
      &quot;product&quot;: [
          {           
              &quot;product&quot;: &quot;adc&quot;,
              &quot;pkgid&quot;: 1124245,
              &quot;wrfid&quot;: 5387612
          }
      ]
  }
  </code></pre>
  <p>Using the below <code>C#</code> code to retrieve the <code>JSON</code> payload.</p>
  <p><em><strong>C#:</strong></em></p>
  <pre><code>var jsondata = new WebClient();
  string prdcode = jsondata.DownloadString(new Uri(url));
  
  JavaScriptSerializer jss = new JavaScriptSerializer
  {
      MaxJsonLength = Int32.MaxValue
  };
  Rootobject ro = jss.Deserialize&lt;Rootobject&gt;(prdcode);
  </code></pre>
  <p>Now, I will have to update the <code>SQL</code> table with <em>packageId</em>, <em>webReferenceId</em> from the <code>JSON</code> output. I am reading <code>JSON</code> results into a <code>DataReader</code> but not sure how to <code>UPDATE</code> the <code>SQL</code> table.</p>
  <pre><code>DataTable dt = new DataTable();
  dt.Columns.Add(new DataColumn(&quot;packageId&quot;, typeof(int)));
  dt.Columns.Add(new DataColumn(&quot;webReferenceId&quot;, typeof(int)));
  DataRow dr = dt.NewRow();
  
  foreach (var product in ro.data)
  {
      dr[&quot;packageId&quot;] = product.pkgid;
      dr[&quot;webReferenceId&quot;] = product.wrfid;
  }
  </code></pre>