I have two datasets, and I need to compare these two datasets, so if the identifier does not exist in the same table, then I need to write the insert query query Query else.
For Ex:
Id in One dataset ID in second Dataset 1 1 2 2 3 4
I need to insert ID 3 into the second dataset.
Here is my code for your reference:
if (ds.Tables[0].Rows.Count > 0 || clientDS.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { for (int j = 0; j < 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() + "')"); } } } }
The above code does not work. Pls fix my problem.
thanks
source share