By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,112 Members | 1,619 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,112 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.