从数据库中获取价值并添加它的价值?

时间:2016-03-17 10:05:16

标签: c# mysql winforms datagridview

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

var register = function(user) {
      return $http.post('/api/register', user).success(function(data){
        saveToken(data.token);
      });
    };

  var  login = function(user) {
      return $http.post('/api/login', user).success(function(data) {
        saveToken(data.token);
      });
    };

   var logout = function() {
      $window.localStorage.removeItem('mean-token');
    };

put var and check it 

enter image description here

1 个答案:

答案 0 :(得分:0)

解决!

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