how to use in data from oracle to calculate on C#?

故事扮演 提交于 2019-12-11 05:34:47

问题


I have a table in Oracle with lots of data. In the structure of:

code_value    date_value     value
1             20/07/2017      10.5
1             19/07/2017      11.6
2             20/07/2017      1000.22
2             18/07/2017      1700.44

I have another table that defines a test for this data: Whose structure is as follows:

code_value      check_rule      check_period    connection_rule
1                16%            w               or
1                30%            m               or
1                50%            y               or
2                130%           w               and
2                110%           6m              and

*p.s. "check_period": w - for week, m - for month, y - for year.
** p.s. I'm still debating if split this column into two columns: one for the amount of time and one for the time type (ex: 6, m).

I would like to take the test table and run it on the table with the data, on C#.
but I don't know how to start to do it:
How do I take a value from a table and use it to calculate? for example:
if I will take the first line, with 16% check_rule, and I will do:
var a = check_rule[0];
How to check whether the increase was 16% per week?
In the same way how to use OR on "connection_rule"?

I'm really hope that my question clear enough.

Thank U!


回答1:


OracleConnection conn = new OracleConnection("Your Connection string");
conn.Open();
DataSet dataSet = new DataSet();
OracleCommand cmd = new OracleCommand(
    "SELECT * FROM TABLE1 t inner join TABLE2 t1 on t.code_value = t1.code_value"
);
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;

using (OracleDataAdapter dataAdapter = new OracleDataAdapter())
{
  dataAdapter.SelectCommand = cmd;
  dataAdapter.Fill(dataSet);
}

DataTable dt = ds.Tables[0];
//loop through table's rows/columns
var myVal = ParseToDouble(dt.Rows["value"].ToString());
var checkRule = ParseToDouble(dt.Rows["check_rule"].ToString());

if(myVal < checkRule)
   doSomething();


public double ParseToDouble(string s)
{
    return decimal.Parse( s.TrimEnd('%') ) / 100M;
}


来源:https://stackoverflow.com/questions/45220498/how-to-use-in-data-from-oracle-to-calculate-on-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!