I have been trying to identify differences between 2 identical format
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;
//Populate dirFiles dataset with a list of file names found in a
specific folder
DirectoryInfo dir = new
DirectoryInfo(currentFileVariables.TemplateFolder.Trim()); //note the
currentFileVariables value is simply a folder name
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;
//Populate wsFiles dataset with a list of file names picked up from a
file
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!!!
--
You received this message because you are subscribed to the Google
Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML
Web Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en
or visit the group website at http://megasolutions.net