我无法更新我的图表

时间:2016-03-03 17:47:21

标签: c# charts tableadapter

我的表格有两个按钮。每个都在数据库的表中生成不同的值。应通过单击每个按钮更新图表,但仅显示程序运行时数据库中的值。表数据显示在datagridview中以验证数据库是否正在更改。我已经尝试过命令.Invalidate()和.Update()但是没有用。

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();
        }

    }
}

0 个答案:

没有答案