Stored Procedure

Discussion in 'ASP .Net' started by Kev, Oct 20, 2004.

  1. Kev

    Kev Guest

    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
     
    Kev, Oct 20, 2004
    #1
    1. Advertising

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

    "Kev" wrote:

    > 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
    >
     
    =?Utf-8?B?QmlsbCBCb3Jn?=, Oct 20, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sarmad Aljazrawi

    New Stored Procedure Template in .Net

    Sarmad Aljazrawi, Dec 16, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    549
    Sarmad Aljazrawi
    Dec 16, 2003
  2. ES
    Replies:
    2
    Views:
    1,546
    jgy3183
    Aug 20, 2004
  3. Patrick
    Replies:
    2
    Views:
    5,985
    Gopinath S
    Feb 15, 2005
  4. Mike P
    Replies:
    0
    Views:
    3,352
    Mike P
    Jun 19, 2006
  5. AlexWare
    Replies:
    2
    Views:
    782
    Paul Uiterlinden
    Oct 23, 2009
Loading...

Share This Page