Hi Kira,
I tried to delete rows from a database using the DataRow.Delete() method, but when i expecting this method to mark the rows as Deleted or Detached it simply removes the DataRow from the DataRow Collection. Do i missed something ?
Here is the code i'm using
public
void Preload()
{
OdbcDataAdapter data_adpt = m_odbccmdb.DataAdapter;
data_adpt.SelectCommand.CommandText = buildQuery();
m_odbccmdb.RefreshSchema();
m_dataset.Clear();
if ((m_maps == null) && (data_adpt.TableMappings == null || data_adpt.TableMappings.Count == 0))
{
m_maps = (
DataTableMapping[])XmlManager.setXml(FileManager.Read(Settings.Default.MappingsPath + ClassName + "_map.xml"), typeof(DataTableMapping[]));
data_adpt.TableMappings.AddRange(m_maps);
}
data_adpt.FillSchema(m_dataset,
SchemaType.Mapped, m_table_name);
data_adpt.FillSchema(m_dataset,
SchemaType.Source, m_table_name);
}
public
void delete(TrackedItems trks)
{
if (string.IsNullOrEmpty(m_xml))
{
throw new NullReferenceException("Xml document is Null or Empty.");
}
else
{
if (m_dataset.DataSetName == "NewDataSet") Preload();
//Load XML into the Dataset
DataSet dataset_temp = m_dataset.Clone();//Copy the Original Dataset with all schema and constraints but without data
StringReader srd = new StringReader(m_xml);
dataset_temp.ReadXml(srd,
XmlReadMode.Auto);
int count=dataset_temp.Tables[0].Rows.Count;
//here Delete removes rows from teh DataRowCollection instead of marking them as Deleted Why?
while (dataset_temp.Tables[0].Rows.Count > 0) dataset_temp.Tables[0].Rows[dataset_temp.Tables[0].Rows.Count-1].Delete();
//Merged incoming data with those previously loaded and compare
m_dataset.Merge(dataset_temp);
//Collects the changes/add/delete into a Trackeditems collection
if (trks != null) trks.TrackChanges(m_dataset);
m_odbccmdb.DataAdapter.Update(m_dataset, m_table_name);
m_dataset.AcceptChanges();
}
}
Thanks you for any assistance on this issue
Eric