Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to insert the value in textbox

C#
int totalexp = Int32.Parse(txtTotalExpPer.Text);


but if field is empty then it gives the error

[edit]pre tag c# code added and Treat my content as plain text, not as HTML is unchecked - PES[/edit]
Posted
Updated 23-Feb-12 23:13pm
v2

Use it
int totalexp ;

int.tryParse(txtTotalExpPer.Text,out totalexp )
 
Share this answer
 
Comments
ProEnggSoft 25-Feb-12 3:12am    
This solution is good. Hence 5!
Have a look at TryParse. http://msdn.microsoft.com/en-us/library/f02979c7.aspx[^]

Good luck!
 
Share this answer
 
Use require validation or check before type conversion .......
 
Share this answer
 
hi there..

try to use required field validator.. or else use this code..

C#
int totalexp = Convert.ToInt32(txtTotalExpPer.Text);


all the best..
 
Share this answer
 
SQL
so...u have to insert the value from totalexp to textbox(i.e,txtTotalExpPer.Text)
right...then use...txtTotalExpPer.Text=totalexp .ToString();...You Can Check The TextBox Is Empty..By Using If()...
 
Share this answer
 
Comments
piushshukla 24-Feb-12 6:50am    
No one works!
Adeyinka Oluwaseun Doyin 25-Feb-12 3:09am    
check my solution to your problem , Solution 6
Use this code , it works... i wrote and tested it.


C#
private void button1_Click(object sender, EventArgs e)
       {

           int expectedResultFormat;
           string ExpPer = txtTotalExpPer.Text; // first pass the value to a string variable
           bool myResult = Int32.TryParse(ExpPer, out expectedResultFormat);
           if (myResult == true) // if conversion was successful
           {
               int totalexp = Int32.Parse(txtTotalExpPer.Text);
           }

           else
           {
               // do something else to it either by setting it to a default value
               MessageBox.Show("Please only numbers are allowed !!! ");
           }
       }
 
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