Click here to Skip to main content
16,018,818 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
sum of textbox values in asp.net.This is My Code

C#
decimal num = Convert.ToDecimal(txtcustomot.Text);
         decimal num2 = Convert.ToDecimal(txtAirfreight.Text);
         decimal num3 = Convert.ToDecimal(txtDocument.Text);
         decimal num4 = Convert.ToDecimal(txtcompt.Text);
         decimal num5 = Convert.ToDecimal(txtairlanka.Text);
         decimal num6 = Convert.ToDecimal(txtcexp.Text);
         decimal num8 = num + num2 + num3 + num4 + num5 + num6;
         lbltotal0.Text = num8.ToString();


I want to handle null value Textbox.exsample txtcustomot.Text is null code not working how to fix this one.any one can help me,

Thank You

How to pass the null value store procedure
parameters[1].Value = Decimal.Parse(txtAirfreight.Text);

This code is not working.
Posted
Updated 30-Sep-13 23:12pm
v2

Hey there,

You could try this example for all your decimal variable assignments:
C#
String.IsNullOrEmpty(txtAirfreight.Text.Trim()) ? 0 : Convert.ToDecimal( txtAirfreight.Text.Trim());
to avoid the Exception.

Hope it helps

Azee...
 
Share this answer
 
try this
C#
decimal num =0,num2=0,num3=0,num4=0,num5=0,num6=0;
         decimal.TryParse(txtcustomot.Text,out num);
         decimal.TryParse(txtAirfreight.Text,out num2);
         decimal.TryParse(txtDocument.Text,out num3);
         decimal.TryParse(txtcompt.Text,out num4);
         decimal.TryParse(txtairlanka.Text,out num5);
         decimal.TryParse(txtcexp.Text,out num6);
         decimal num8 = num + num2 + num3 + num4 + num5 + num6;
         lbltotal0.Text = num8.ToString();
 
Share this answer
 
Comments
[no name] 1-Oct-13 5:17am    
How to pass the null value store procedure
parameters[1].Value = Decimal.Parse(txtAirfreight.Text);

This code is not working.
Zafar A khan 1-Oct-13 5:43am    
decimal proval=0;
decimal.TryParse(txtAirfreight.Text,out proval);
parameters[1].Value = (proval==0)?"NULL":proval;
Textbox.text=null

but convert to decimal of it maynot be zero
 
Share this answer
 
Don't use Convert: use decimal.TryParse instead:
C#
decimal num;
decimal.TryParse(txtcustomot.Text, out num);
If it fails, it will leave zero in the num variable (and return false, so you could report a problem if necessary)
 
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