.Net Framework 1.1 - Merge files not identifying Deleted rows

S

stainless

I have been trying to identify differences between 2 identical data
tables in 2 datasets so that new rows in my second file would be
identified as Added and those missing from my second file but in the
first would be identified as Deleted.

The issue I have is that the rows i expected to be Deleted are being
flagged as unchanged.

My code is below:

string currentFileName;

//Create a list of files in the folder

DataColumn dirDataColumn = new DataColumn();
dirDataColumn.DataType = System.Type.GetType("System.String");
dirDataColumn.ColumnName = "Filename";
dirDataColumn.ReadOnly=true;
dirDataColumn.Unique= true;


DataSet dirFiles;
dirFiles = new DataSet();
DataTable dirTab = new DataTable();
dirTab.Columns.Add(dirDataColumn);
DataColumn[] dirCol = new DataColumn[1];
dirCol[0] = dirTab.Columns["Filename"];
dirTab.PrimaryKey = dirCol;

currentFileVariables =
ReadConfig.ReadUserDetails(SystemInformation.UserName);

DirectoryInfo dir = new
DirectoryInfo(currentFileVariables.TemplateFolder.Trim());

if (dir.Exists == true)
{

FileInfo[] files = dir.GetFiles("*.sql");

foreach (FileInfo file in files)
{
currentFileName = file.Name.ToString().Trim();
DataRow newDirRow = dirTab.NewRow();
newDirRow["Filename"]=currentFileName;
dirTab.Rows.Add(newDirRow);
}
}

dirFiles.Tables.Add(dirTab);


//Create a list of files recorded in a text file previously

DataColumn wsDataColumn = new DataColumn();
wsDataColumn.DataType = System.Type.GetType("System.String");
wsDataColumn.ColumnName = "Filename";
wsDataColumn.ReadOnly=true;
wsDataColumn.Unique= true;


DataSet wsFiles;
wsFiles = new DataSet();
DataTable wsTab = new DataTable();
wsTab.Columns.Add(wsDataColumn);
DataColumn[] wsCol = new DataColumn[1];
wsCol[0] = wsTab.Columns["Filename"];
wsTab.PrimaryKey = wsCol;

foreach(WorkSpace ws in frm.workSpaceCollection)
{
if(ws.Name==frm.TEMPLATES_WORKSOURCE)
{
foreach(WorkSpaceSubGroup sg in ws.WorkSpaceSubGroups)
{
foreach(WorkSpaceItem file in sg.WorkSpaceItems)
{
currentFileName = file.FileName.Trim();
DataRow newWsRow = wsTab.NewRow();
newWsRow["Filename"]=currentFileName;
wsTab.Rows.Add(newWsRow);
}
}
}
}

wsFiles.Tables.Add(wsTab);

//Compare the 2 files via the following steps:
//1. Create a merge file of the filenames I have in my text file and
accept changes
//2. Merge this with the list of files currently in the folder
//3. get the changes from this merge
//4. Any with RowState Added, add to a new file called InsertsFile
//5. Any with RowState Deleted, add to a new file called DeletesFile

DataSet mergeFiles = new DataSet();
DataSet insertsFile = new DataSet();
DataSet deletesFile = new DataSet();

mergeFiles.Merge(wsFiles);
mergeFiles.AcceptChanges();

mergeFiles.Merge(dirFiles);

insertsFile = mergeFiles.GetChanges(DataRowState.Added);

deletesFile = mergeFiles.GetChanges(DataRowState.Deleted);


Given the following rows (I have this exact data):
wsFiles wsTab: file2_name.sql
file3_name.sql
dirFiles dirTab: file1_name.sql
file3_name.sql


I expected these to be identified in the Merge as follows:

file1_name.sql - Added (as was not in wsFiles but was in dirFiles)
file2_name.sql - Deleted (as was in wsFiles but not in dirFiles)
file3_name.sql - Unchanged (in both with no text diffferences)

What I actually get is:
file1_name.sql - Added
file2_name.sql - Unchanged
file3_name.sql - Modified

I am very puzzled!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top