hi there, im very much new in programming, and i'm having a hard time in comparing two datafiles using c#, when im adding the while loop it doesnt work, but when i remove it, it compares the first line of my datafile, what i want to do it to compare my datafile line by line... heres my code, hope you could help me on this one, thank you in advance:)...
private void match_Click(object sender, EventArgs e)
{
//string f1, f2;
try
{
string fileName = @"C:\PRJ2000_LFSDATA\file1.DAT";
string filename2 = @"C:\PRJ2000_LFSDATA\file2.DAT";
StreamReader sr = new StreamReader(fileName);
StreamReader sr2 = new StreamReader(filename2);
StreamWriter SW = File.CreateText("c:\\temp\\MyTextFile.txt");
while ((!sr.EndOfStream) && (!sr2.EndOfStream))
{
if ((x.Substring(12, 2)) == (x2.Substring(12, 2))) //PRV
{
if ((x.Substring(14, 2)) == (x2.Substring(14, 2)))//MUN
{
if ((x.Substring(16, 3)) == (x2.Substring(16, 3)))//BGY
{
if ((x.Substring(19, 3)) == (x2.Substring(19, 3)))//EA
{
if ((x.Substring(27, 4)) == (x2.Substring(27, 4)))//SHSN
{
if ((x.Substring(31, 4)) == (x2.Substring(31, 4)))//HCN
{
//SW.Write("HCN Equal" + "\t\nf1= " + sr.ReadLine().Substring(1, 21) + sr.ReadLine().Substring(27, 4) +
// "\t\nf2= " + sr2.ReadLine().Substring(1, 21) + sr2.ReadLine().Substring(27, 4));
//SW.Write("\n");
//SW.Close();
}
else
{
SW.Write("HCN not Equal" + "\t\nf1= " + sr.ReadLine().Substring(1, 35) + " " + sr.ReadLine().Substring(27, 4) +
"\t\nf2= " + sr2.ReadLine().Substring(1, 35) + " " + sr2.ReadLine().Substring(27, 4));
SW.Write("\n");
SW.Close();
}
}
else
{
SW.Write("SHSN not Equal" + "\r\n f1= " + sr.ReadLine().Substring(1, 35) + " " + sr.ReadLine().Substring(27, 4) +
"\r\n f2= " + sr2.ReadLine().Substring(1, 35) + " " + sr2.ReadLine().Substring(27, 4));
SW.Write("\n");
SW.Close();
}
}
}
}
}
}
System.Diagnostics.Process.Start(@"C:\temp\MyTextFile.txt");
//MessageBox.Show("database READ");
sr.Close();
sr2.Close();
}
catch
{
MessageBox.Show("error Running");
}
}