Stored Procedure

K

Kev

Can anyone help me determine why I am getting the error "Object must
implement IConvertible" when I execute the stored procedure? The
exception is InvalidCastException. Below is the code. I have checked
the stored procedure, database table column datatype and the sqldbtype
and they are identical. The only thing that is not the same is the
datatype of the @col1 and @col2 parameter in the server explorer where
it is shown as "adnumeric", not sure if that is a problem or not. So I
am a little lost here. Any assistance is greatly appreciated.:

objConn.open
objCom = New SqlCommand("UPLOAD_A", objConn)
objCom.CommandType = CommandType.StoredProcedure

With objCom.Parameters
..Add("@col1", SqlDbType.Decimal, 9)
..Add("@col2", SqlDbType.Decimal, 5)
..Add("@col3", SqlDbType.VarChar, 6)
..Add("@Count", SqlDbType.Int)
End With

With objCom
..Parameters("@col1").Value = dt.Columns(0)
..Parameters("@col1").Precision = 11
..Parameters("@col1").Scale = 2
..Parameters("@col2").Value = dt.Columns(1)
..Parameters("@col2").Precision = 5
..Parameters("@col2").Scale = 4
..Parameters("@col3").Value = dt.Columns(2)
..Parameters("@Count").Direction = ParameterDirection.Output
End With

If objCom.ExecuteNonQuery() > 0 Then
'uploaded records
Dim iCount As Integer
iCount = objCom.Parameters("@Count").Value
Console.WriteLine(iCount)
Console.ReadLine()
Return True
Else
Return False
End If
 
G

Guest

Kev, you are assigning *datacolumns* to your parameter values, when what you
need is the *data* in those datacolumns, converted to your decimal, string,
etc. Because the parameters collection takes only generic objects, the system
can't catch this till you run it.

Bill
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top