Input string was not in a correct format

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all!!

Working on a datgrid, codeing for my update button. When it trys to update
I get the input string error.
Here is part of my code, where I'm having problems.

.Add(New SqlParameter("@ProductName", _
SqlDbType.NVarChar, 40)).Value = txtProductName
.Add(New SqlParameter("@SupplierPart", _
SqlDbType.NVarChar, 50)).Value = txtSupplier
.Add(New SqlParameter("@UnitCost", _
SqlDbType.Money, 8)).Value = CDbl(txtCost)
.Add(New SqlParameter("@UnitSRP", _
SqlDbType.Money, 8)).Value = CDbl(txtSRP)
.Add(New SqlParameter("@UnitsInStock", _
SqlDbType.Int)).Value = CInt(txtInStock)
.Add(New SqlParameter("@Discontinued", _
SqlDbType.Bit)).Value = chkDiscontinued.Checked
'.Add(New SqlParameter("@New", _
' SqlDbType.Bit)).Value = chkNew.Checked
.Add(New SqlParameter("@Used", _
SqlDbType.Bit)).Value = chkUsed.Checked

Any thoughts?

Thanks!

Rudy
 
It looks like you're trying to convert a textbox to a double and string,
etc.
You should really be trying to convert the Text property of the textbox.

This is not correct:
..Value = CDbl(txtCost)

This is correct:
..Value = CDbl(txtCost.Text)
 
You didn't say which line was the problem specifically, but I would guess
one of your CDbl calls is failing. It is either getting an empty string, or
a string that cannot be interpreted as a number.
 
Perfect guys!

Thank You

Steve C. Orr said:
It looks like you're trying to convert a textbox to a double and string,
etc.
You should really be trying to convert the Text property of the textbox.

This is not correct:
..Value = CDbl(txtCost)

This is correct:
..Value = CDbl(txtCost.Text)
 
Btw, using Option Strict On, would avoid most of these kinds of problems at
compile time instead of runtime.
 
Back
Top