I am building this C# windows application. On a certain Form, I am using maskedtextbox to enter upto 3 numerical digits, then I convert it into int as I have to send all these data to database with an insert query, but the problem is that these maskedtextboxes give error when left empty:
int scd_user_comm = Convert.ToInt32(maskedTextBox1.Text);
and the error is :
Input string was not in a correct format.
The corresponding field in database allows null, so if left empty, it must not give an error. Can anyone help please?
One side question:: Can I use a textbox or maskedtextbox to ensure that user only enters numeric value b/w 0 to 100? Thanks in advance.
You could try the Int32.TryParse() method
this will give you all the flexiblity required to work with your integer var and your maschedTextBox-
To force your maskTextBox to accept only numeric values set
However this is not enough to ensure the enterd number is between 0 and 100.
To get this result you need to use the Validating event and reject the input if is outside your limits