简体   繁体   中英

C# calculate amount with values from datarows

    public string getKlantreferte(string rr, string kbo, string name)
    {

        if (rr != "")
        {
            return rr;
        }

        if (kbo != "")
        {
            return kbo;
        }

        if (name != "")
        {
            return name;
        }

        return "";

    }



    public void setText(string changetext) //Automatically appends text in richtextbox
    {
        rtb.AppendText($"{changetext}{Environment.NewLine}");
        Application.DoEvents();
    }

    string klantreferte = "";
    public double calculateSchadebeding(DataTable dt, string klantreferte)
    {
        double schadebeding = 0;

        foreach (DataRow row in dt.Rows) ;
         {

         }


        return schadebeding;
    }

        //loop over datatable

        // if klantreferte == getKlantreferte(....) 
        //--> schadebding + Datarow[4]

        //if klantreferte != getKlantreferte
        //--> create a new calculation


        // then calculate 10% of the 'schadebeding'
        // Then check if schadebeding 40 >     --> return 40,     if 40 <    --> return schadebeding

I need help with a function that calculates a value through very specific parameters. I understand what needs to happen as you will see in //comment of my code. Though, whenever I try to implement it practically I seem to hit a brick wall. I already wrote the loop over the datatable, but the "if" parameters is what gets me.

Hi eventually you can use table.Compute-function: --> ADO.NET

private void ComputeBySalesSalesID(DataSet dataSet)
{
    // Presumes a DataTable named "Orders" that has a column named "Total."
    DataTable table;
    table = dataSet.Tables["Orders"];

    // Declare an object variable.
    object sumObject;
    sumObject = table.Compute("Sum(Total)", "EmpID = 5");
}

You can set a condition as second param here it is EmpID = 5

See also here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM