Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从数据库中获取价值并添加其价值?_C#_Mysql_Winforms_Datagridview - Fatal编程技术网

C# 从数据库中获取价值并添加其价值?

C# 从数据库中获取价值并添加其价值?,c#,mysql,winforms,datagridview,C#,Mysql,Winforms,Datagridview,我有一个datagridview,我从phpmyadmin调用值,我尝试添加它的值行,但当我编辑单元格时,它得到相同的值 MySqlConnection conn = new MySqlConnection("datasource=localhost;port = 3306;username = root;password = "); MySqlCommand comm = new MySqlCommand("select Fee,Amount from syste

我有一个datagridview,我从phpmyadmin调用值,我尝试添加它的值行,但当我编辑单元格时,它得到相同的值

       MySqlConnection conn = new MySqlConnection("datasource=localhost;port = 3306;username = root;password = ");
        MySqlCommand comm = new MySqlCommand("select Fee,Amount from system.other_school_fees ;", conn);

            MySqlDataAdapter ssda = new MySqlDataAdapter();
            ssda.SelectCommand = comm;
            DataTable ddbdataset = new DataTable();
            ssda.Fill(ddbdataset);
            BindingSource bbsource = new BindingSource();

            bbsource.DataSource = ddbdataset;
            dataGridView2.DataSource = bbsource;
            ssda.Update(ddbdataset);
            dataGridView2.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

            int d = 0;
            for (int b = 0; b < dataGridView2.Rows.Count; b++)
            {
                d += Convert.ToInt32(dataGridView2.Rows[b].Cells[1].Value);
            }

            lblOSF.Text = d.ToString();
解决了

    private int CellSum()
    {
               string a = string.Empty;
            int sum = 0;
            for (int b = 0; b < dataGridView1.Rows.Count; ++b)
            {
                try
                {
                    int d = 0;
                    d += Convert.ToInt32(dataGridView1.Rows[b].Cells[1].Value);
                    sum += d;
                }
                catch 
                {
                    MySqlConnection conn = new MySqlConnection("datasource=localhost;port = 3306;username = root;password = ");
                    MySqlCommand comm = new MySqlCommand("select Miscellaneous_Fee,Amount from system.miscellaneoues;", conn);

                    MySqlDataAdapter ssda = new MySqlDataAdapter();
                    ssda.SelectCommand = comm;
                    DataTable ddbdataset = new DataTable();
                    ssda.Fill(ddbdataset);
                    BindingSource bbsource = new BindingSource();

                    bbsource.DataSource = ddbdataset;
                    dataGridView1.DataSource = bbsource;
                    ssda.Update(ddbdataset);
                    dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

                    MessageBox.Show("Incorrect Input");
                }

            }
            return sum;     

    }

 private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
    {

        if (e.ColumnIndex == 1)
            lblMiscellaneous.Text = CellSum().ToString();
    }

w8应该是MySqlConnection conn=new MySqlConnectiondatasource=localhost;端口=3306;用户名=根;密码=;MySqlCommand comm=new MySqlCommandselect杂项费用,来自system.miscellaneoues;的金额;,康涅狄格州;您是否有编辑单元格后运行的代码?不幸的是,它不会重新计算自己。