Input string was not in a correct format

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
 
S

Steve C. Orr [MVP, MCSD]

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)
 
M

Marina

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.
 
G

Guest

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)
 
M

Marina

Btw, using Option Strict On, would avoid most of these kinds of problems at
compile time instead of runtime.
 

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

Top