Note that there are some explanatory texts on larger screens.

plurals
  1. POCompare two datasets in C#
    primarykey
    data
    text
    <p>i have two datasets and i need to compare these two datasets such that if ID does not exist in one table then i need to write insert Query else update query.</p> <p>For Ex:</p> <pre><code>Id in One dataset ID in second Dataset 1 1 2 2 3 4 </code></pre> <p>I need to insert ID 3 to second dataset.</p> <p>Here is my code for your reference:</p> <pre><code>if (ds.Tables[0].Rows.Count &gt; 0 || clientDS.Tables[0].Rows.Count &gt; 0) { for (int i = 0; i &lt; ds.Tables[0].Rows.Count; i++) { for (int j = 0; j &lt; clientDS.Tables[0].Rows.Count; j++) { if (ds.Tables[0].Rows[i]["Id"].ToString() == clientDS.Tables[0].Rows[j]["Id"].ToString()) { client.GetSingleValue("update customers set Name='" + ds.Tables[0].Rows[i]["Name"].ToString() + "',ContactPerson= '" + ds.Tables[0].Rows[i]["ContactPerson"].ToString() + "',Address='" + ds.Tables[0].Rows[i]["Address"].ToString() + "',TinNo='" + ds.Tables[0].Rows[i]["TinNo"].ToString() + "',ContactNo='" + ds.Tables[0].Rows[i]["Contactno"].ToString() + "',Report= '" + ds.Tables[0].Rows[i]["Report"].ToString() + "',Sync=0,Ids='" + ds.Tables[0].Rows[i]["Id"].ToString() + "' where id='" + ds.Tables[0].Rows[i]["Id"].ToString() + "' "); } else { client.GetSingleValue("insert into customers(id,Name,ContactPerson,Address,TinNo,ContactNo,Report,Sync,Ids) values('" + ds.Tables[0].Rows[i]["Id"].ToString() + "', '" + ds.Tables[0].Rows[i]["Name"].ToString() + "','" + ds.Tables[0].Rows[i]["ContactPerson"].ToString() + "', '" + ds.Tables[0].Rows[i]["Address"].ToString() + "', '" + ds.Tables[0].Rows[i]["TinNo"].ToString() + "', '" + ds.Tables[0].Rows[i]["Contactno"].ToString() + "', '" + ds.Tables[0].Rows[i]["Report"].ToString() + "',0,'" + ds.Tables[0].Rows[i]["Id"].ToString() + "')"); } } } } </code></pre> <p>Above code does not work. Pls rectify my issue.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload