Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assign quoted null values to integer

Status
Not open for further replies.

trenta87

Programmer
Oct 29, 2007
13
US
Im creating a program where users need to fill out a form with a number of textboxes. Ive created all the correct classes and some variables are integer types. The thing is i want to be able to have some textboxes left blank the program will still create an instance of a class and this information saved to access database. I get an error message saying conversion from type string "" to interger is invalid! Is there a way i can bypass this error and still have null values assigned to an integer???
 
From what you said, I'm guessing that you get the error when you try to convert the contents of the textbox to an integer to add it to the database. If that's the case, then add a check before making the conversion.
 
You need to catch the null value ("") and pass Nothing to the data table instead of trying to pass "".

If TextBox1.Text = "" Then
paramValue.Value = Nothing
Else
paramValue.Value = TextBox1.Text
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top