Click here to Skip to main content
15,890,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to insert a selected value from a combo-box (Win forms)

I have two combo boxes that use different data type (Int and tinyint)

Data Type int is working

What I have tried:

For INT code is working
<pre>eventInfo.PersonDetailModuleID = Convert.ToInt32(cboPersonDetailModule.SelectedValue.ToString())


For TinyInt code is not working
eventInfo.ChildPersonDetailModuleID = Convert.ToByte(cboPersonDetailModuleChild.SelectedValue.ToString())


DAL

parms[2] = new SqlParameter("@PersonDetailModuleID", SqlDbType.Int, 4,ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, businessObject.PersonDetailModuleID);
parms[3] = new SqlParameter("@ChildPersonDetailModuleID", SqlDbType.TinyInt,1, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, businessObject.ChildPersonDetailModuleID);


Error OR Warning:
FormatException was unhandled

An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Input string was not in a correct format
Posted
Updated 18-Sep-18 23:09pm

Start with the debugger, and look at what is in your SelectedValue.

The documentation - Convert.ToByte Method (System) | Microsoft Docs[^] - says that the FormatException occurs when it contains a non-numeric value otehr than '-', or when the string is empty. So start with the debugger and check exactly what you are passing to Convert.ToByte.
 
Share this answer
 
Thank you OriginalGriff when I populate my combo box I used a wrong ValueMember primaryID from the combobox that use INT

I used
cboPersonDetailModuleChild.ValueMember = "PersonDetailModuleID";<pre>
instead of
cboPersonDetailModuleChild.ValueMember = "ChildPersonDetailModuleID";
 
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