bit to bool

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

    #1

    bit to bool

    Greeting,
    i receive from db parameter in bit format
    and tried to convert it to boolean:
    bool boolBhcg=(bool) prmBhcg.Value;

    as result i receive msg:

    Description: An unhandled exception occurred during the execution of the
    current web request. Please review the stack trace for more information
    about the error and where it originated in the code.

    Exception Details: System.InvalidC astException: Specified cast is not valid.

    does anyone meet this problem before?


  • Frank Oquendo

    #2
    Re: bit to bool

    Mike wrote:
    [color=blue]
    > does anyone meet this problem before?[/color]

    A bool can only have one of two values: true or false. Unlike other
    languages, a non-zero value does not indicate a true condition. Try
    something like this instead:

    bool boolBhcg = (prmBhcg.Value != 0);

    --
    There are 10 kinds of people. Those who understand binary and those who
    don't.


    (Pull the pin to reply)


    Comment

    • Michael Culley

      #3
      Re: bit to bool

      you could try something like:

      bool boolBhcg = ((int) prmBhcg.Value == -1);


      --
      Michael Culley


      "Mike" <bladox@hotmail .com> wrote in message news:uvOyl8urDH A.556@TK2MSFTNG P11.phx.gbl...[color=blue]
      > Greeting,
      > i receive from db parameter in bit format
      > and tried to convert it to boolean:
      > bool boolBhcg=(bool) prmBhcg.Value;
      >
      > as result i receive msg:
      >
      > Description: An unhandled exception occurred during the execution of the
      > current web request. Please review the stack trace for more information
      > about the error and where it originated in the code.
      >
      > Exception Details: System.InvalidC astException: Specified cast is not valid.
      >
      > does anyone meet this problem before?
      >
      >[/color]


      Comment

      Working...