Input string was not in a correct format.

R

rn5a

A sub-routine retrieves the value in a TextBox (which ought to be an
integer) which in turn resides in a DataGrid (actually the column is a
BoundColumn which changes to a TextBox when the DataGrid is in the
editable mode). This is the code:

-----------------------------------
Dim strQty As String
Dim iQty As Integer

strQty = CType(ea.Item.Cells(5).Controls(0), TextBox).Text
iQty = CInt(strQty)
-----------------------------------

The last line iQty = CInt(strQty) generates the following error:

Input string was not in a correct format.

What's wrong with the last line in the above code?
 
S

Scott M.

The problem is here:

strQty = CType(ea.Item.Cells(5).Controls(0), TextBox).Text
iQty = CInt(strQty)

What if the user does not enter a value at all? Or, what if the value
entered is not convertable to an Integer? You need to verify that the data
entered into the textbox is indeed numeric before attempting to convert it
to an Integer.
 
J

Jon Paal [MSMD]

use trace, or some such method, to output the value of "strQty" before the conversion to see what is being returned.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top