Home All Groups Group Topic Archive Search About

Error: Cast From String to type Integer not valid

Author
1 Jul 2005 5:47 PM
Michael
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

Author
1 Jul 2005 5:58 PM
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
Author
1 Jul 2005 6:26 PM
Michael
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

Show quoteHide quote
"Cor Ligthert" wrote:

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