The CF Whisperer recommended this:
"Avoid DataTables. They are gigantic memory hogs, and under CE you can't afford a memory hog. Basically it duplicates the entire source table into RAM for you. SqlCeDataReader and SqlCeResultSet are your friends."
...regarding this code:
var dt = new DataTable();
dt.Columns.Add(new DataColumn("Id", typeof(Int32)));
dt.Columns.Add(new DataColumn("DeptNumber", typeof(Int32)));
dt.Columns.Add(new DataColumn("DeptName", typeof(string)));
foreach (HHSUtils.Department dept in depts)
{
try
{
dt.Rows.Add(dept.Id, dept.DeptNumber, dept.DeptName);
countAdded++;
}
catch (Exception ex)
{
MessageBox.Show(string.Format("deptId == {0}, deptNumber == {1},
deptName == {2} ({3})", dept.Id, dept.DeptNumber, dept.DeptName, ex.Message));
}
}
// Now move it all into the table
using (var bc = new SqlCeBulkCopy(dataSource))
{
bc.DestinationTableName = "Departments";
bc.WriteToServer(dt);
}
I don't understand how I'm to replace DataTable with SqlCeDataReader or SqlCeResultSet here. My code above with DataTable is DDL and doesn't seem to be equate (in my mind) to SqlCeDataReader or SqlCeResultSet, as their purpose is (reputedly?) for working with queried data...???