Cannot implicitly convert type 'object' to 'bool' Error

Discussion in 'ASP .Net' started by Patrick Olurotimi Ige, Jan 25, 2005.

  1. When i convert:- this code from VB to C#
    Why do i get error "Cannot implicitly convert type 'object' to 'bool'


    VB
    ---
    If cmdcommand.Parameters("ReturnValue").Value = 1 Then
    lblStatus.Text = "Username already exists!"
    Else
    lblStatus.Text = "Success!"
    End If


    to

    C#
    ---
    if (cmdcommand.Parameters["ReturnValue"].Value == 1) {
    lblStatus.Text = "Username already exists!";
    } else {
    lblStatus.Text = "Success!";
    }

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Patrick Olurotimi Ige, Jan 25, 2005
    #1
    1. Advertising

  2. Patrick Olurotimi Ige

    bruce barker Guest

    cmdcommand.Parameters["ReturnValue"].Value return an object. you can not
    compare objects to numbers. if you know the type of the return value, then
    you can cast it, and do the compare

    if ( (int) cmdcommand.Parameters["ReturnValue"].Value == 1)

    this will throw an error is the parameter is no really an int.





    "Patrick Olurotimi Ige" <> wrote in message
    news:...
    | When i convert:- this code from VB to C#
    | Why do i get error "Cannot implicitly convert type 'object' to 'bool'
    |
    |
    | VB
    | ---
    | If cmdcommand.Parameters("ReturnValue").Value = 1 Then
    | lblStatus.Text = "Username already exists!"
    | Else
    | lblStatus.Text = "Success!"
    | End If
    |
    |
    | to
    |
    | C#
    | ---
    | if (cmdcommand.Parameters["ReturnValue"].Value == 1) {
    | lblStatus.Text = "Username already exists!";
    | } else {
    | lblStatus.Text = "Success!";
    | }
    |
    | *** Sent via Developersdex http://www.developersdex.com ***
    | Don't just participate in USENET...get rewarded for it!
     
    bruce barker, Jan 25, 2005
    #2
    1. Advertising

  3. Thx Bruce..
    That worked like a charm!




    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Patrick Olurotimi Ige, Jan 25, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Sutorius
    Replies:
    9
    Views:
    20,584
    Kevin Spencer
    Feb 22, 2005
  2. Patrick Olurotimi Ige
    Replies:
    3
    Views:
    8,743
    Patrick Olurotimi Ige
    May 4, 2005
  3. John Mair
    Replies:
    1
    Views:
    162
    Robert Klemme
    Nov 2, 2010
  4. Replies:
    11
    Views:
    260
    Dave Angel
    Apr 26, 2013
  5. dave em
    Replies:
    3
    Views:
    121
    Chris Angelico
    Feb 6, 2014
Loading...

Share This Page