471,592 Members | 1,332 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,592 software developers and data experts.

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.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!
Nov 19 '05 #1
2 6578
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" <ig*@iprimus.com.au> wrote in message
news:eY**************@tk2msftngp13.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.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!
Nov 19 '05 #2
Thx Bruce..
That worked like a charm!


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

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by Christoph Boget | last post: by
2 posts views Thread by Jeff | last post: by
9 posts views Thread by Andy Sutorius | last post: by
2 posts views Thread by Christophe | last post: by
2 posts views Thread by Nick | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.