cannot implicitly convert to bool

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nick

    #1

    cannot implicitly convert to bool

    I am trying to find out if particular array element contains InputOutput
    value.

    private static int FillParameters( DbCommand command, SqlParameter[] p)
    {
    int x = 0; //int initalize to hold zero
    for (int i = 0; i < p.Length; i++)
    {
    command.Paramet ers.Add(p[i]);
    if (p[i].Direction = ParameterDirect ion.InputOutput ) <<<==
    error here
    x = i;
    }
    }

    but I am getting errors as follows:

    Error 39 Cannot implicitly convert type 'System.Data.Pa rameterDirectio n' to
    'bool' C:\IList_WareHo use_Solution\Da taObjects\Db.cs 277 22 DataObjects

    all I want to know is if p[i].Direction contains the value InputOutput but I
    guess am comparing it wrong. Any suggestions?

    nick
  • Bill Rodenbaugh

    #2
    Re: cannot implicitly convert to bool

    You are mising the seconf =

    this: if (p[i].Direction = ParameterDirect ion.InputOutput )
    should be if (p[i].Direction == ParameterDirect ion.InputOutput )


    On Nov 3, 11:43 am, Nick <N...@discussio ns.microsoft.co mwrote:
    I am trying to find out if particular array element contains InputOutput
    value.
    >
    private static int FillParameters( DbCommand command, SqlParameter[] p)
    {
    int x = 0; //int initalize to hold zero
    for (int i = 0; i < p.Length; i++)
    {
    command.Paramet ers.Add(p[i]);
    if (p[i].Direction = ParameterDirect ion.InputOutput ) <<<==
    error here
    x = i;
    }
    }
    >
    but I am getting errors as follows:
    >
    Error 39 Cannot implicitly convert type 'System.Data.Pa rameterDirectio n' to
    'bool' C:\IList_WareHo use_Solution\Da taObjects\Db.cs 277 22 DataObjects
    >
    all I want to know is if p[i].Direction contains the value InputOutput but I
    guess am comparing it wrong. Any suggestions?
    >
    nick

    Comment

    • Jianwei Sun

      #3
      Re: cannot implicitly convert to bool

      Nick wrote:
      I am trying to find out if particular array element contains InputOutput
      value.
      >
      private static int FillParameters( DbCommand command, SqlParameter[] p)
      {
      int x = 0; //int initalize to hold zero
      for (int i = 0; i < p.Length; i++)
      {
      command.Paramet ers.Add(p[i]);
      if (p[i].Direction = ParameterDirect ion.InputOutput ) <<<==
      error here
      x = i;
      }
      }
      >
      but I am getting errors as follows:
      >
      Error 39 Cannot implicitly convert type 'System.Data.Pa rameterDirectio n' to
      'bool' C:\IList_WareHo use_Solution\Da taObjects\Db.cs 277 22 DataObjects
      >
      all I want to know is if p[i].Direction contains the value InputOutput but I
      guess am comparing it wrong. Any suggestions?
      >
      nick
      you should use == instead of =

      It's nice that the compiler will give you this error. In C++, it will
      silently assign the value to p[i].Direction, then , it will be an run
      time error instead of compiler - time error.

      Comment

      Working...