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); Equation = Equation.Replace("C.P.", txtCP.text); Equation = Equation.Replace("S.P.", txtSP.text);
Equation = Equation.Replace("GAIN", txtGain.text);
Equation = Equation.Replace("LOSS", txtLoss.text);
Equation = "Select " + Equation;

**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!