0

I am trying to update an sql column to show the percentage by dividing a column of real type (Amount) by a variable of double type (Total) which is calculated earlier and has a value, however I am confused how to write the statement.

Below code gives an error saying no column with name Total exists which is a value not a column!

Thanks in advance.

SqlCommand percent = new SqlCommand("UPDATE QuantitiesTable SET percgrosvol = (Amount/Total)", ccn);

percent.ExecuteScalar();
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
zizobiko25
  • 33
  • 7

1 Answers1

0

So you have a variable Total in your C# code and you want to pass it to the query.

Then, you just need to pass the parameter value to the command:

SqlCommand percent = new SqlCommand("UPDATE QuantitiesTable SET percgrosvol = Amount/@Total", ccn);
percent .Parameters.AddWithValue("@Total", Total);
percent.ExecuteScalar();