how to reference value in DataColumn Expressions


  • I have an existing expression like this

        DataTable1.Columns.Add("value", typeof(double), "rate * loan_amt");

    in a datatable with 10000 rows where rate is same for all rows and loan_amt varies

    When the rate changes, it changes for all
    currently that means iterating through all rows like so

         foreach(DataRow dr in DataTable1.Rows) dr["rate"] = new_rate;

    wondering if there's a better way using a ReferenceTable (with only 1 row ) in the same DataSet and linking it somehow like so

         DataTable1.Columns.Add("value", typeof(double), "RefTable.Row0.rate * loan_amt");

    so changing the rate would be as simple as

         RefTable.Rows[0]["rate"] = new_rate;

    Or is there any other way ?

    • Modifié kumarnyc vendredi 2 mars 2012 22:14
    vendredi 2 mars 2012 22:13


  • Hi,

    you'd have to create a parent table with the one rate record (using a relation),

    create all your records refrencing the one record,

    and in the expression use:

    Parent.Rate * loan_amt

    Regards, Nico

    lundi 5 mars 2012 08:37

Toutes les réponses