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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Patrick Olurotimi Ige

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

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


    VB
    ---
    If cmdcommand.Para meters("ReturnV alue").Value = 1 Then
    lblStatus.Text = "Username already exists!"
    Else
    lblStatus.Text = "Success!"
    End If


    to

    C#
    ---
    if (cmdcommand.Par ameters["ReturnValu e"].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

    #2
    Re: Cannot implicitly convert type 'object' to 'bool' Error

    cmdcommand.Para meters["ReturnValu e"].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.Para meters["ReturnValu e"].Value == 1)

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





    "Patrick Olurotimi Ige" <ige@iprimus.co m.au> wrote in message
    news:eYG6qYnAFH A.3836@tk2msftn gp13.phx.gbl...
    | When i convert:- this code from VB to C#
    | Why do i get error "Cannot implicitly convert type 'object' to 'bool'
    |
    |
    | VB
    | ---
    | If cmdcommand.Para meters("ReturnV alue").Value = 1 Then
    | lblStatus.Text = "Username already exists!"
    | Else
    | lblStatus.Text = "Success!"
    | End If
    |
    |
    | to
    |
    | C#
    | ---
    | if (cmdcommand.Par ameters["ReturnValu e"].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!


    Comment

    • Patrick Olurotimi Ige

      #3
      Re: Cannot implicitly convert type 'object' to 'bool' Error

      Thx Bruce..
      That worked like a charm!




      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      Working...