Click here to Skip to main content
15,885,992 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
if (Convert.ToInt32(txtTvalidqty.Text) > Convert.ToInt32(txtPlanQty.Text))
Posted
Updated 3-Jan-13 22:16pm
v3
Comments
CPallini 4-Jan-13 4:15am    
And the question is?
Abhishek Pant 4-Jan-13 4:16am    
if ((Convert.ToInt32(txtTvalidqty.Text)) > (Convert.ToInt32(txtPlanQty.Text)))
Suvabrata Roy 4-Jan-13 4:17am    
What is the problem / error
Master Vinu 4-Jan-13 4:17am    
not working ) expected
Abhishek Pant 4-Jan-13 4:22am    
try above one I wrote above and if this doesn worked then try CPallini's option of exceptionn handling

When converting text into numerical values, you should always use the Parse methods rather than the Convert methods.
C#
int value1;
int value2;

Int32.Parse(txtTvalidqty.Text, out value1);
Int32.Parse(txtPlanQty.Text, out value2);

if (value1 > value 2) ...
 
Share this answer
 
Comments
Aarti Meswania 4-Jan-13 4:42am    
5+
fjdiewornncalwe 4-Jan-13 10:21am    
Thanks, Aarti.
[no name] 4-Jan-13 5:45am    
*****
fjdiewornncalwe 4-Jan-13 10:21am    
Thanks, Turbo_23
[no name] 4-Jan-13 10:27am    
hi marcus i have one question can you please check it "http://www.codeproject.com/Questions/521548/Convertplus2dplusImageplusintoplus3dplusinplusasp"
if (Convert.ToInt32(txtTvalidqty.Text) > Convert.ToInt32(txtPlanQty.Text))

-- Check Null value first for both txtTvalidqty.Text and txtPlanQty.Text like this.


C#
if (string.IsNullOrEmpty(txtTvalidqty.Text)) 
{
   txtTvalidqty.Text="0";
}
if (string.IsNullOrEmpty(txtPlanQty.Text))
{
   txtPlanQty.Text="0";
}

if (Convert.ToInt32(txtTvalidqty.Text) > Convert.ToInt32(txtPlanQty.Text))


Hope, this helps.
--
Thanks,
Abhay Bansal
 
Share this answer
 
v4
Comments
fjdiewornncalwe 4-Jan-13 4:37am    
You should never check for null or empty in this fashion. Use if(string.IsNullOrEmpty(txtTvalidqty.Text)) notation instead.
You will also still get the error that the input string is incorrect format because the wrong converters are being used. See my answer for the correct way to do this.
Yo can first check the text in textbox like
if(Convert.ToString(txtTvalidqty.Text)!=null && Convert.ToString(txtTvalidqty.Text)!="" && Convert.ToString(txtPlanQty.Text)!=null && Convert.ToString(txtPlanQty.Text)!="")
{
if ((Convert.ToInt32(txtTvalidqty.Text) > Convert.ToInt32(txtPlanQty.Text))
{
//your code
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900