Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ASP.NET

I've a textbox which should accept null(textbox is empty). But the null value is not inserting in database(sql server). The error is "Input string was not in a correct format". The coding is
C#
int BusinessNumber = Convert.ToInt32(txtBusinessNumber.Text);

if .ToString() is not working.
Posted
Updated 18-Oct-13 22:29pm
v2

 
Share this answer
 
Comments
Siva Hyderabad 19-Oct-13 5:03am    
try this

Convert.ToInt32(txtBusinessNumber.Text.Trim().ToString());
Sriram Ramachandran 19-Oct-13 5:39am    
no its not working ......... Same error.........Input string is not in a correct format .....
You have to check whether there is an actual value in your textbox, and if it is convertible to Int32. This way:
C#
int BusinessNumber;
if (!string.IsNullOrEmpty(txtBusinessNumber.Text) && int.TryParse(txtBusinessNumber.Text, out BusinessNumber)) {
   // TextBox contains a valid Int32 value
}
else {
   // TextBox is empty or does not contain a valid Int32 value
}
 
Share this answer
 
v4

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