Query return comparison with "N" status

Asked

Viewed 166 times

-1

I need help for comparison in "if" c# of a datatable database return.

Below the code snippet:

public class ArcerarDto
{
    public DataTable SelectArcerarContract()
    {
        ArcerarDal arcerarObj = new ArcerarDal();
        DataTable arcerarDt = arcerarObj.SelectArcerar();


        if (arcerarDt.Rows[0][2].ToString() = 'N') ///// erro aqui
        {
            //logFile "ERRO", "Contrato do xxx está Inativo."
            //aborta processamento
        } 
  • 3

    And what is the doubt?

  • 1

    Well I don’t know yet if it’s the best way to compare plus an equal sign is assignment and two equals sign together is comparison, so your code might just be typo.

  • thank you Virgilio!

  • 2

    Can’t even compare string to char do... == "N"

  • Thank you so much for your help! It worked

2 answers

2

if (arcerarDt.Rows[0][2].ToString() = 'N')// erro

Equal operator in C#: ==. Using "=" is when you will set some value to a variable or property. In the case of IF / ELSE it is used operand "==" (equality operator).

if (arcerarDt.Rows[0][2].ToString() == "N")// correto

0

Check if there is one missing "=" on the stretch below:

if (arcerarDt.Rows[0][2].ToString() **==** 'N')

Browser other questions tagged

You are not signed in. Login or sign up in order to post.