0

Using ASP.NET razor and SQL Server 2008 R2

I have a local variable that is declared thus:

var tsmMtd = db.QueryValue("  
  SELECT  b.Name, SUM(subtotal) totalSUM  
  FROM DR_TRANS a  
  INNER JOIN Staff b ON a.Salesno = b.Staffno  
  WHERE a.salesno in (12,23,28,30)  
    AND a.TRANSDATE >= dateadd(m, datediff(m, 0, getdate()), 0)   
    AND a.REF3 = 'Invoice'  
  GROUP BY b.Name  
  ORDER BY totalSUM DESC  
");

Now that returns an array of names from the table, sorted by sales value. calling it in the HTML later as

@tsmMtd.ToString()  

which prints the topmost name. OK, all good. NOW....

I need to format the text of the page based on that top salesperson. I want their name to go blue if they are the top salesperson.This is what I did on the 'actual sales' figure for a salesperson:

<span class=@(salesval12  > 6000 ? "blue" : "red")>@salesval12.ToString("C")</span>  

This works fine to change the colour of the text if it is over the 6000 value. (classes red and blue are defined higher up the page). So, I did this:

<span class=@(tsmMtd = "CHARLIE JONES" ? "blue" : "red")>Charlie</span>  

but it fails at loading saying Compiler Error Message: CS0029: Cannot implicitly convert type 'string' to 'bool'

OK, so what I need to know is

  1. what I am doing wrong
  2. what I should be doing

Any and all help much appreciated.

1 Answer 1

2

Instead of

@(tsmMtd = "CHARLIE JONES" ? "blue" : "red")

It should be

@(tsmMtd == "CHARLIE JONES" ? "blue" : "red")

You wrote one equal sign instead of two. With one it just save CHARLIE JONES to tsmMtd variable and then try to compare that string variable as condition and compiler display an error about it

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.