I'm trying to write a tool to compare a database with a textfile. It should get the data from the PostgreSQL database and check if the textfile contains the value of the database coloumn.
It should Show all values from the database, if they are contained in the Textfile. Example: If the Name "a" is in the textfile, it should Show "a" and other data from the database in the wpf datagrid.
Here is my Code for the ceck up:
string connStr = "Server=" + Globals.server + ";Port=" + Globals.port + "; Database=" + Globals.db + ";User Id=" + Globals.user + ";Password=" + Globals.passwd + ";";
NpgsqlConnection conn = new NpgsqlConnection(connStr);
conn.Open();
NpgsqlCommand nda = new NpgsqlCommand("select name,ip_address,location from public.\"smartq_devices\"", conn);
using (StreamReader sr = File.OpenText(Globals.sFilename))
{
string[] lines = File.ReadAllLines(Globals.sFilename);
for (int x = 0; x < lines.Length - 1; x++)
{
NpgsqlDataReader myReader = nda.ExecuteReader();
while (myReader.Read())
{
if (lines[x].Contains(myReader["name"].ToString()))
{
//MessageBox.Show(lines[x]);
DataRow newRow = dtResult1.NewRow();
newRow["Hostname"] = myReader["name"].ToString();
newRow["Ip address"] = myReader["ip_address"].ToString();
newRow["Location"] = myReader["location"].ToString();
dtResult1.Rows.Add(newRow);
}
}
}
dgViewDevices.ItemsSource = dtResult1.AsDataView();
}
When i execute this code i get some data in the datagrid but there are some blank lines in between. I added a Picture of the result.
I don't know where I have the error or even the wrong Approach.
Thank you in advance for your help.