c# - How can I use a SQL value in a formula -


i have c# winform app, contains formula. formula works ok depending on id sql table numbers in formula can change.

how can accomplish this?

the code have is:

private void button1_click(object sender, eventargs e)  {     decimal ufa1;     decimal aav1;      decimal uft1;      ufa1 = uft1 * aav1 * value sql;   } 

i have previous query gets value want can't integrated in formula.

the code id is:

con.open(); sqlcommand cmd = con.createcommand(); cmd.commandtype = commandtype.text; cmd.commandtext = "select prumos dbo.modelos id = '"+id+"'"; sqldatareader dr = cmd.executereader(); 

new code: because of dependencies had change select id column named "prumos" int values id wont run.

    con.open();     using (sqlcommand cmd = new sqlcommand("select prumos dbo.modelos prumos = @prumos", con))     {         cmd.parameters.add(new sqlparameter("prumos", prumos));         valuefromdb = decimal.parse(cmd.executescalar().tostring());     } 

any solutions?

private void button1_click(object sender, eventargs e)  {     decimal ufa1;     decimal aav1;      decimal uft1;      con.open();     sqlcommand cmd = con.createcommand();     cmd.commandtype = commandtype.text;     cmd.commandtext = "select prumos dbo.modelos id = '"+id+"'";     //sqldatareader dr = cmd.executereader();     //decimal valuefromdb = (decimal)cmd.executescalar();     decimal valuefromdb = decimal.parse(cmd.executescalar().tostring());       ufa1 = uft1 * aav1 * valuefromdb ;   } 


or better:

    private void button1_click(object sender, eventargs e)     {         decimal ufa1;         decimal aav1;         decimal uft1;         decimal valuefromdb;          using (sqlcommand cmd = new sqlcommand("select prumos dbo.modelos id = @id", con))         {             cmd.parameters.add(new sqlparameter("id", id));             valuefromdb = decimal.parse(cmd.executescalar().tostring());          }         ufa1 = uft1 * aav1 * valuefromdb;     } 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -