How to Make Local Changes to an ADO.NET* DataSet in a Mobilized Application

Submit New Article

December 9, 2008 11:00 PM PST



Challenge

Update the local version of the data used in a mobilized ADO.NET application. Mobilized applications require the ability to operate on local versions of data offline that can subsequently be updated on a server.


Solution

To insert a row in a DataTable, create a DataRow object using the DataTable’s NewRow method, add the data to DataColumns, and finally add the DataRow to the DataTable’s Rows collection. The following operations outline how the data operations are achieved locally on the DataSet:

  • Insert row
  • Update data in a row
  • Delete selected row

 

The following code enacts those operations:

DataRow dr;
dr = MyDataSet.Tables[0].NewRow();
dr[0] = 123;
dr[1] = "New Name For Example";
MyDataSet.Tables[0].Rows.Add(dr);

dr[2] = 99; //access by column index
dr["Column Name") = 88;

dr.BeginEdit();
dr[2] = 99;
dr[3] = "New Value";
dr.EndEdit();

dr.Delete();

 

This item may be most useful when used in conjunction with the following, separate items:

 


Sources

Data Synchronization with the ADO.NET* DataSet

Identifying and Extracting Data Changes in the ADO.NET* Dataset