My Form has two buttons. Each generates different values in a table in the database. The chart should be updated by clicking on each button, but appears only the values that were in the database at the time the program was run. The table data are displayed in a datagridview to validate whether the database is being changed. I've tried the commands .Invalidate() and .Update() but did not work.
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; using System.Data.OleDb; namespace FrmtabGraf { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { TODO: This line of code loads data into the 'lojaDataSet.Dados' table. You can move, or remove it, as needed. this.dadosTableAdapter.Fill(this.lojaDataSet.Dados); } void FillTable1() { Conexao ca = new Conexao(); string sql = ""; sql += " Insert Into Dados "; sql += " (Descricao, Quantidade) "; sql += " Select "; sql += " d.Defeito, COUNT(d.Defeito) AS quantidade "; sql += " From "; sql += " (SisIndice s INNER JOIN "; sql += " Defeitos d ON s.idDefeito = d.idDefeito) "; sql += " WHERE (s.DataFat BETWEEN "; sql += " #" + "01/01/2001" + "# "; sql += " AND "; sql += " #" + "31/12/2006" + "#) "; sql += " GROUP BY d.Defeito "; ca.Conectar(); OleDbCommand cd = new OleDbCommand(sql, ca.cx); try { cd.ExecuteNonQuery(); } catch (OleDbException x) { MessageBox.Show(x.Message); } ca.Desconectar(); } void FillTable2() { Conexao ca = new Conexao(); string sql = ""; sql += " Insert Into Dados "; sql += " (Descricao, Quantidade) "; sql += " Select "; sql += " d.Defeito, COUNT(d.Defeito) AS quantidade "; sql += " From "; sql += " (SisIndice s INNER JOIN "; sql += " Defeitos d ON s.idDefeito = d.idDefeito) "; sql += " WHERE (s.DataFat BETWEEN "; sql += " #" + "01/01/2001" + "# "; sql += " AND "; sql += " #" + "31/12/2015" + "#) "; sql += " GROUP BY d.Defeito "; ca.Conectar(); OleDbCommand cd = new OleDbCommand(sql, ca.cx); try { cd.ExecuteNonQuery(); } catch (OleDbException x) { MessageBox.Show(x.Message); } ca.Desconectar(); } void ReadTable() { Conexao ca = new Conexao(); string sql = ""; sql += " Select "; sql += " Quantidade, Descricao "; sql += " From Dados "; ca.Conectar(); OleDbDataAdapter da = new OleDbDataAdapter(sql, ca.cx); DataSet ds = new DataSet(); da.Fill(ds, "Dados"); dgvTable.DataSource = ds.Tables["Dados"]; ca.Desconectar(); } void ClearTable() { Conexao ca = new Conexao(); string sql = ""; sql += " Delete * From Dados "; ca.Conectar(); OleDbCommand cd = new OleDbCommand(sql, ca.cx); try { cd.ExecuteNonQuery(); } catch (OleDbException x) { MessageBox.Show(x.Message); } ca.Desconectar(); } private void cmdDados1_Click(object sender, EventArgs e) { ClearTable(); FillTable1(); ReadTable(); } private void cmdDados2_Click(object sender, EventArgs e) { ClearTable(); FillTable2(); ReadTable(); } } }
Last edited by a moderator: