I need to get the column names after the query in order to display them in the dataGridView1 component.
To obtain and fill in the table column names I use:
dataGridView1.Rows.Clear(); dataGridView1.Columns.Clear(); object a = comboBox1.SelectedItem; sql = "SELECT column_name FROM information_schema.columns WHERE table_name = '" + a + "'"; NpgsqlCommand com = new NpgsqlCommand(sql, con); con.Open(); NpgsqlDataReader reader; reader = com.ExecuteReader(); ArrayList nameColumns = new ArrayList(); while (reader.Read()) { try { nameColumns.Add(reader.GetValue(0)); } catch { } } dataGridView1.ColumnCount = nameColumns.Count; for (int i = 0; i < nameColumns.Count; i++) { dataGridView1.Columns[i].HeaderText = nameColumns[i].ToString(); } con.Close(); But how to get the name of the columns with the result of the query, given that the query for multiple tables?