Pretty much stuck on this for the past few days. I wouldn't normally post here but what I'm trying to come up with just searching on my own doesn't work. I want to query PostgreSQL and come up with multiple records that each have multiple fields (indicated by my SELECT statement). Since I don't know the # of records returned I figured some sort of while loop was best. I just cant seem get all my values as a list and then throw that list into a table, adding rows as needed.
NpgsqlConnection pgconn = new NpgsqlConnection(ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString);
pgconn.Open();
NpgsqlCommand command = new NpgsqlCommand("SELECT line, oper, subst_a, from_loc, to_loc, area " +
"FROM ab_basedata.superpipes_ihs " +
"WHERE gdm_approv = '" + lic_num_lbl + "'", pgconn);
List<List<string>> pipes = new List<List<string>> { };
NpgsqlDataReader dr = command.ExecuteReader();
while (dr.Read())
{
pipes.Add("Line: " + dr.GetValue(0) + " " + dr.GetValue(1) + " " + dr.GetValue(2) + " " + dr.GetValue(3) + " " + dr.GetValue(4) + " " + dr.GetValue(5) + " Office");
foreach (List<string> pip in pipes)
{
TableRow row = new TableRow();
TableCell cell1 = new TableCell();
cell1.Text = string.Join(" ", pipes);
row.Cells.Add(cell1);
docTable.Rows.Add(row);
}
}