Click here to Skip to main content
15,887,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to store the textbox value by its database field.. I have a combo box with student numbers that, when selected-loads the corridor name and residence name of that selected student into text boxes.

when i call the insert method

bo.AddEquipmentToStoreRoom(Convert.ToDateTime(lblDate.Text), Convert.ToDateTime(lblTime.Text), option1, txtStoreBarcode.Text, Convert.ToInt32(txtCorridorName.Text), Convert.ToString(cmbStudentNumber.SelectedValue), Convert.ToInt32(cmbDescription.SelectedValue));


it returns an error message saying "input string was not in a correct format"... Please help. Thanks.
Posted
Comments
TrushnaK 17-Sep-13 3:53am    
Debuge and Check values in this line:-
Convert.ToInt32(txtCorridorName.Text), Convert.ToString(cmbStudentNumber.SelectedValue),

1 solution

When facing problems like this, the debugger is probably the best tool you'll have at your hands.

1) Put one breakpoint at the sentence where the exception is thrown.
2) Let the code run until your breakpoint is hit.
3) Use the quick watch debug view to evaluate each expression involved in the sentence,
4) After determining the piece of code that fails, correct it
5) Test the code again and repeat from step 2) if needed.

In your case, most surely the problem is caused by some malformed string passed as parameter to one of the Convert method calls in your code. You'll have to check them all individually.

Perhaps you should consider adding some sort of input validation mechanism in our 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