Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Npgsql;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.SqlClient;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace WindowsFormsApp2
- {
- public partial class ReportTable : Form
- {
- NpgsqlConnection con;
- int clientID;
- private void Update()
- {
- DataSet ds = new DataSet();
- DataTable dt = new DataTable();
- SqlDataReader dr;
- NpgsqlDataAdapter da;
- string sql = "Select * from clients";
- da = new NpgsqlDataAdapter(sql, con);
- ds.Reset();
- da.Fill(ds);
- dt = ds.Tables[0];
- comboBoxClientName.DataSource = dt;
- comboBoxClientName.DisplayMember = "name";
- comboBoxClientName.ValueMember = "clientID";
- //comboBoxClientName.SelectedValue = clientID.ToString();
- UpdateorderEntries();
- }
- private void UpdateorderEntries()
- {
- DataSet ds = new DataSet();
- DataTable dt = new DataTable();
- SqlDataReader dr;
- NpgsqlDataAdapter da;
- string sqlorderEntries = "SELECT orders.orderID, goods.name, price*amount AS cost FROM orders LEFT JOIN orderEntries ON orders.clientID = :clientID AND orderEntries.orderID = orders.orderID JOIN goods ON goods.goodID = orderEntries.goodID WHERE delivered = false";
- NpgsqlCommand command = new NpgsqlCommand(sqlorderEntries, con);
- command.Parameters.AddWithValue("clientID", comboBoxClientName.SelectedValue);
- da = new NpgsqlDataAdapter(command);
- ds.Reset();
- da.Fill(ds);
- dt = ds.Tables[0];
- dataGridView1.DataSource = dt;
- }
- public ReportTable()
- {
- InitializeComponent();
- con = new NpgsqlConnection("Server=localhost;Port=5432;User Id=postgres;Password=masterkey;Database=lemmaITDB");
- con.Open();
- }
- private void ReportTable_Load(object sender, EventArgs e)
- {
- Update();
- }
- private void ReportTable_FormClosed(object sender, FormClosedEventArgs e)
- {
- }
- private void comboBoxClientName_SelectedIndexChanged(object sender, EventArgs e)
- {
- Update();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement