12,560,555 members (57,399 online)
Rate this:
See more:
I Wanted to store the formula text and intend to evaluate the formulae and display results of the operation..
Thanks a lot
Posted 18-Nov-12 4:48am
OriginalGriff 18-Nov-12 11:24am

What have you tried? What have you got to store so far? Where are you stuck?

Rate this:

## Solution 3

you can do this way...

store formula in sql table tblFormulas like below...
```FormulaName  			FormulaEquation
Gain				S.P. - C.P.
Loss				C.P. - S.P.
Gain%				(GAIN * 100)/C.P.
Loss%			         (LOSS * 100)/S.P
Selling Price (S.P)                 ((100 + GAIN%)/100)*C.P.```
Now...
Write down code in .net
replace values of parameters in equations...
for e.g.
```string Equation = "((100 + GAIN%)/100)*C.P.";
Equation = Equation.Replace("GAIN%", txtGainPer.text); // suppose txtGainPer.text = 50
Equation = Equation.Replace("C.P.", txtCP.text); // suppose txtGainPer.text = 27
Equation = Equation.Replace("S.P.", txtSP.text);
Equation = Equation.Replace("GAIN", txtGain.text);
Equation = Equation.Replace("LOSS", txtLoss.text);
//result will be like below... Equation = "((100 + 50)/100)*27";
//now send this equation to sql as below to evaluate
Equation = "Select " + Equation;
//then pass string to sql for execution...```
NOTE : This code is vulnerable for sql injection
TIP: to avoid this you can use third party .net classes available for evaluate expressions OR can write code for evaluate expressions your self

Hope this helped you.
Happy Coding!
:)
Maciej Los 23-May-14 1:56am

+5!
Welcome back Aarti!
Aarti Meswania 23-May-14 2:58am

Thank you, Maciej Los :)
Rate this:

## Solution 1

If I am not wrong; you want to store some sql in a field and execute it.

```Declare @a varchar(999)

set @a='select 5*5+5'
--You can use select @a=fieldname from tablename where criterya

Exec (@a)```

Top Experts
Last 24hrsThis month
 OriginalGriff 146 John Simmons / outlaw programmer 60 CPallini 45 Afzaal Ahmad Zeeshan 35 F-ES Sitecore 35
 OriginalGriff 4,688 Suvendu Shekhar Giri 1,943 John Simmons / outlaw programmer 1,935 ppolymorphe 1,725 CPallini 1,309