Error: Cast From String to type Integer not valid

G

Guest

I need some help. I have the following code:
cmSQL = New SqlCommand("nf_AddPurchaseOrder", cnSQL)
cmsql.CommandType = CommandType.StoredProcedure
cmsql.Parameters.Add("@PurchaseOrderId", sqldbtype.varchar, 10,
"OrderNo").Value = txtPONum.Text
cmsql.Parameters.Add("@OrderDesc", sqldbtype.VarChar , 50 ,
"OrderDesc").Value = txtOrderDescription.text
cmsql.Parameters.Add("@SupplierId", sqldbtype.Int , "SupplierId").Value =
s.SupplierId
Dim b as Program
b = cmbPrograms.SelectedItem
cmsql.Parameters.Add("@ProgramId", sqldbtype.Int , "ProgramId").Value =
b.ProgramId

When the code hits either the SupplierId or the ProgramId line I get the
following error:
Cast from String "SupplierId" to type 'Integer' is not valid
My problem is that the stored procedures parameters are Int, the values I'm
passing in are also Integers. So not sure where the heck this error is coming
from. Thanks for any help.
Michael Lee
 
C

Cor Ligthert

Michael,

VBNet has those nice conversions methods.

dim a as integer = Cint("1") is all you have to do to make from a string
containing only numbers and by instance decimal points a nice integer.

I hope this helps,

Corn
 
G

Guest

Hi Cor,
Thanks for the reply. I just found the problem, it was my mistake. If I
change the following code:
cmsql.Parameters.Add("@SupplierId", sqldbtype.Int , "SupplierId").Value =
s.SupplierId
TO:
cmsql.Parameters.Add("@SupplierId", sqldbtype.Int).Value = s.SupplierId

It works fine. I had gotten the wrong overloaded method.
Thanks for the reply.
Michael
 

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