tags:

views:

22

answers:

2

I use codes below to inserts values to database by executing stored procedure.

 Dim connstring As String = "dsn=test"
 Dim oConn As Odbc.OdbcConnection = New Odbc.OdbcConnection(connstring)
 Dim com As New Odbc.OdbcCommand("{? = call sp_test1(?,?,?,?)}", oConn)
 com.CommandType = CommandType.StoredProcedure
 com.Parameters.AddWithValue("@Code", 2)
 com.Parameters.AddWithValue("@Name", "2")
 com.Parameters.AddWithValue("@Familly", "2")
 com.Parameters.AddWithValue("@Pname", "2")
 oConn.Open()
 com.ExecuteNonQuery()
 oConn.Close()

but I got this error

ERROR [HY105] [Microsoft][ODBC SQL Server Driver]Invalid parameter type

and here is my stored procedure

USE [test]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

Create Procedure [dbo].[sp_test1]
 @Code bigint,
 @Name nvarchar(50),
 @Familly nvarchar(50),
 @Pname nvarchar(50),
    As
    Begin
 Insert Into test1
  ([Code],[Name],[Familly],[Pname])
 Values
  (@Code,@Name,@Familly,@Pname)

 Declare @ReferenceID int
 Select @ReferenceID = @@IDENTITY

 Return @ReferenceID

 End

is there a solution ?

A: 

At the first glance, the stored procedure has the 1st parameter of type bigint whereas it is given a string value in form of an input.

com.Parameters.AddWithValue("@Code", "2")

Change the above to

com.Parameters.AddWithValue("@Code", 2)

Does that work?

EDIT: Can you change this line

Dim com As New Odbc.OdbcCommand("{? = call sp_test1(?,?,?,?)}", oConn)

to

Dim com As New Odbc.OdbcCommand("sp_test1", oConn)

shahkalpesh
no . I test it but I have the same error yet.
Mahsa
in add with value I think it doesent matter if I use "2" or 2. the value is important to be number.
Mahsa
A: 

no I test Dim com As New Odbc.OdbcCommand("sp_test1", oConn) but it doesent work

Mahsa