I have one SharePoint List. From Excel I will store the values in Data-table and fetch the values to List.If new values are adding to list is no problem.

If item is already there i want to update the item to list.

In my Datatable here I was changed the CanNum -1 to CanNum -update. So I want to compare sharepoint list items and datatable. In datatble I want to store only modified values after I want to update in list.

Here is my code :

if (oItems != null)
                                 ///Item updating
                                 Hashtable htValues = new Hashtable();
                                 string ID = oItems.ID.ToString();
                                 foreach (SPListItem items in sqlfields)
                                     string columns = items["Title"].ToString();
                                     string columns1 = items["Fields"].ToString();

                                         DataTable changedRecordsTable = dt.GetChanges(DataRowState.Modified);

                                         if (changedRecordsTable!=null)
                                             if (changedRecordsTable.Columns.Contains(Sqlcolumns))
                                               if (!htValues.Contains(columns1 ))
                 htValues.Add(columns1 , dr[columns]);


                                 ///Using AddUpdateSqlItem method Update Product list witH SQL data's.
                                 oItems = UpdateItem(currWeb, olistname, ID, htValues);

I was tried this DataTable changedRecordsTable = dt.GetChanges(DataRowState.Modified); changedRecordsTable comes null.

In hashtable i want to add only modified values.

Based on that image i want to store only txtCan_ReqNum value to hastable.

How can i do this.Someone help for this. Thanks in Advance.

  • Someone please Give me any suggestion or solution for this.
    – elina
    Commented Aug 19, 2016 at 12:39

1 Answer 1


After adding or updating the value in datatable, you need to update it using below line.


I think you need to update the value in datatable & than after store it to the hashtable. so you will get the modified data.

below line will get the modified data from datatable

DataTable changedRecordsTable = dt.GetChanges(DataRowState.Modified);

After that you will get the result in changedRecordsTable

Please try this and let me know if it won't work.

  • I was tried this but changedRecordsTable was coming null.
    – elina
    Commented Aug 22, 2016 at 13:18
  • If nothing is changed in dt than you will get null (nothing) by using dt.GetChanges.
    – Hardik
    Commented Aug 22, 2016 at 13:19
  • No, the values are changed but also i was getting null.
    – elina
    Commented Aug 22, 2016 at 13:20
  • After getting the data into datatable you need to update values than after you need to use dt.acceptchanges to get the modified data into dt.GetChanges.
    – Hardik
    Commented Aug 22, 2016 at 13:21
  • From Excel i was getting data and store it in Datatable.The code was written in TimerJob.When the Timerjob runs what are the data's in Excel it will fill to dt .How it will know which are modified data?
    – elina
    Commented Aug 22, 2016 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.