c# - Getting value from database and add it's Value? -


i have datagridview , call values phpmyadmin , try add it's value row when edit cell1 gets same value

       mysqlconnection conn = new mysqlconnection("datasource=localhost;port = 3306;username = root;password = ");         mysqlcommand comm = new mysqlcommand("select fee,amount 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;             (int b = 0; b < datagridview2.rows.count; b++)             {                 d += convert.toint32(datagridview2.rows[b].cells[1].value);             }              lblosf.text = d.tostring(); 

enter image description here

solved!

    private int cellsum()     {                string = string.empty;             int sum = 0;             (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 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();     } 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -