Question How can I not update my chart

ld07

New member
Joined
Mar 3, 2016
Messages
2
Programming Experience
Beginner
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:
You had messed up your xcode tag by using other tags within it. There's no need to use font and colour tags in general. The default font and colour is perfectly readable. Only use other fonts and/or colours and the like for specific emphasis. If you want to use other formatting on code snippets then use code rather than xcode tags.
 
Why are you using OleDb types directly when the code in your Load event handler indicates clearly that you have a typed DataSet? What's the point of having a typed DataSet if you don't use it? With regards to your issue, I'm guessing that your chart is bound to that typed DataSet and none of your code makes any changes to it after the initial load so that would be why your chart never changes.
 
Hi jmcilhinney!

I'm using OleDb Types to enter data in the database. This can interfere with the implementation of the chart?









How could I make changes after the initial charge of the program?



I'm sorry ignorance, I am newbie to C #.
 
I'm using OleDb Types to enter data in the database.
But why, if you have a typed DataSet? You should be using one or the other, not both.
This can interfere with the implementation of the chart?
If what I think is happening is actually happening, it's not that it's interfering. It's that you base the chart on one set of data and you never change that so the chart never changes, while making changes to another set of data and expecting that to affect the chart that it has no relation to.

What is the data source for your chart? Is it the lojaDataSet that you populate in the Load event handler? If so then to change your chart you would have to make changes to that, which you never do. If you want to use a typed DataSet then use it, i.e. ALL your database interactions go through that typed DataSet and its associated table adapters. If you want to use OleDb types directly then do so EXCLUSIVELY and get rid of your typed DataSet.
 
Back
Top Bottom