using Npgsql; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace db_lab { public partial class RaportForm : Form { NpgsqlConnection connection; private void load_data() { try { connection.Open(); string sql = @"SELECT ead.id AS interaction_id, e.name AS equipment_name, r.room_name AS room_name, d.name AS department_name, b.address AS building_address, ead.arrival_date, ead.departure_date FROM Equipment_Arrival_Departure ead JOIN Equipment e ON ead.equipment_id = e.id JOIN Rooms r ON e.room_id = r.id JOIN Department d ON r.building_id = d.building_id JOIN Building b ON d.building_id = b.id; "; NpgsqlDataAdapter adapter = new NpgsqlDataAdapter(sql, this.connection); DataSet dataset = new DataSet(); adapter.Fill(dataset, "data"); dataGridView1.DataSource = dataset.Tables["data"]; connection.Close(); } catch (Exception ex) { MessageBox.Show($"Error! Log: {ex.Message}"); connection.Close(); } } public RaportForm(string connection) { this.connection = new NpgsqlConnection(connection); InitializeComponent(); load_data(); } } }