Results 1 to 5 of 5
Like Tree2Likes
  • 1 Post By jmcilhinney
  • 1 Post By jmcilhinney

Thread: How can I not update my chart

  1. #1
    ld07 is offline C# Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Mar 2016
    Posts
    2
    Rep Power
    0

    How can I not update my chart

    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 jmcilhinney; 03-03-2016 at 5:31 PM. Reason: Fixed code formatting.

  2. #2
    jmcilhinney is offline C# Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2011
    Posts
    1,468
    Rep Power
    118
    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.
    ld07 likes this.

  3. #3
    jmcilhinney is offline C# Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2011
    Posts
    1,468
    Rep Power
    118
    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.
    ld07 likes this.

  4. #4
    ld07 is offline C# Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Mar 2016
    Posts
    2
    Rep Power
    0
    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 #.

  5. #5
    jmcilhinney is offline C# Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2011
    Posts
    1,468
    Rep Power
    118
    Quote Originally Posted by ld07 View Post
    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.
    Quote Originally Posted by ld07 View Post
    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.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •