below is the source code that retrieves database data and stores inside DataTable and will be written to textfile. Therefore, I managed to saves the record on the textfile, but there were duplicate data as shown below.
loggo2.txt
122222 08-0943-03 123333 08-0943-03 122222 08-0943-03 123333 08-0943-03 122222 08-0943-03 123333 08-0943-03 122222 08-0943-03 123333 08-0943-03 122222 08-0943-03 123333 08-0943-03
And what I wanted is this output:
122222 08-0943-03 123333 08-0943-03
However, I would like to remove duplicate before writing to textfile so that next time I can store inside the database without any duplication, please help
foreach (DataRow row1 in dt.Rows)
{
if (row["Material"].ToString().ToLower().Contains(row1["Material"].ToString().ToLower()))
{
//// if match, then write the result
string filename1 = "loggo2.txt";
filename1 = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filename1);
using (StreamWriter w = File.AppendText(filename1))
{
var line = String.Format("{0} {1}", row1["Component"], row1["Material"]);
w.WriteLine(line);
}
}
}