Convertion question

Hi, I am trying to convert the following code but I am getting some error message. Does it look right? Please advise.

VB:
If lblRec1.Text <> "" And ddlAcct1.SelectedValue <> "" Then Call UpdateCustAccount(lblRec1.Text, IIf(ddlAcct1.SelectedValue = "", 0, ddlAcct1.SelectedValue))

C#
if (lblRec1.Text != "" && ddlAcct1.SelectedValue != ""){ UpdateCustAccount (lblRec1.Text,(ddlAcct1.SelectedValue == "") ? 0 : ddlAcct1.SelectedValue);}
avi7Asked:
Who is Participating?
 
rawinnlnx9Commented:
If I convert the C# to VB this is what I get:

if (lblRec1.Text != "" && ddlAcct1.SelectedValue != ""){ UpdateCustAccount (lblRec1.Text,(ddlAcct1.SelectedValue == "") ? 0 : ddlAcct1.SelectedValue);}
0
 
ALaRivaCommented:
What is the error message you are getting?
0
 
avi7Author Commented:
The error is:
Error The best overloaded method match for 'UpdateCustAccount (int, int)' has some invalid argument
For this part of the code:      
{ UpdateCustAccount (lblRec1.Text,(ddlAcct1.SelectedValue == "") ? 0 : ddlAcct1.SelectedValue);}
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
rawinnlnx9Commented:
If I convert the C# to VB this is what I get:

If lblRec1.Text <> "" AndAlso ddlAcct1.SelectedValue <> "" Then
	UpdateCustAccount (lblRec1.Text,If(ddlAcct1.SelectedValue = "", 0, ddlAcct1.SelectedValue))
End If

Open in new window

0
 
avi7Author Commented:
Sorry for convision by I am trying to convet from VB to C# and it's where I have problem.. So you are saying that my C# code is correct?
0
 
rawinnlnx9Commented:
I get errors converting the VB to C# you posted. When I take your C# and converted it to VB I got no errors.  So that's how I approached your problem. I first took your C# as it is and converted it to VB. Then I took the VB and covnerted it back to C# and got the same code.
0
 
avi7Author Commented:
So what are you saying do I have a problem or not?
0
 
ALaRivaCommented:
The problem is that it's reading one of your values as NOT an [int] datatype.

Try parsing the return of your x?0:y return as an INT.

hth
0
 
avi7Author Commented:
Can you please show me on my code example since I am doing something here but I am not sure if it's correct. Thanks!
0
 
avi7Author Commented:
Here is something else that might help to see what I am trying to do:
private void UpdateCustAccount (int strRecID, int strAcct)
0
 
Todd GerbertIT ConsultantCommented:
The UpdateCustAccount method expects to parameters, both int's (aka Int32, or Integer in VB).  You're trying to pass strings to this method.
0
 
avi7Author Commented:
Should I use something like this Convert.ToInt32(ddlAcct1.SelectedValue)  
0
 
Todd GerbertIT ConsultantCommented:
Yes,  or Int32.Parse or Int32.TryParse. I think you have another question open on that topic, which has some good comments.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.