Newbie Question on parameters passed to stored procedure

G

Guest

Hi All,

I am trying to pass parameters to a stored procedure from vb.net code and
fails with the error that the variable is not a parameter to the stored
procedure

Here is the vb.net cod
----------------------------------------------------------------------------------------------
command = New SqlCommand("sp_updateProducts")
command.Connection = connection
command.CommandType = CommandType.StoredProcedure
command.Transaction = trans
command.Parameters.Add(New SqlParameter("@pMacId",
SqlDbType.Char))
command.Parameters.Add(New SqlParameter("@pProdDt",
SqlDbType.DateTime))
command.Parameters.Add(New SqlParameter("@pProdInfo",
SqlDbType.VarChar))
command.Parameters(0).Direction = ParameterDirection.Input
command.Parameters(1).Direction = ParameterDirection.Input
command.Parameters(2).Direction = ParameterDirection.Input
command.Parameters(0).Value = machineID
command.Parameters(1).Value = updateDate
command.Parameters(2).Value = joinStr
command.ExecuteNonQuery()

-----------------------------------------------------------------------------------------------

Here is the stored procedure code:

-----------------------------------------------------------------------------------------------
CREATE PROCEDURE dbo.sp_updateProducts
(
@pMachineId AS CHAR(6),
@pProdDt AS DATETIME,
@pProdinfo VARCHAR(4000)
)
AS
BEGIN
.......
.......
.......
END
G
-----------------------------------------------------------------------------------------------

The error message occurs on ExecuteNonQuery() and says that @pMacId is not a
prameter to the stored procedure sp_updateProducts

I may be missing something very naive! Could anybody suggest the cause of
the error?

Thanks
kd
 
L

Larry Lard

kd said:
Hi All,

I am trying to pass parameters to a stored procedure from vb.net code and
fails with the error that the variable is not a parameter to the stored
procedure

Here is the vb.net code [snips]
command.Parameters.Add(New SqlParameter("@pMacId",
SqlDbType.Char))
Here is the stored procedure code:
@pMachineId AS CHAR(6),
The error message occurs on ExecuteNonQuery() and says that @pMacId is not a
prameter to the stored procedure sp_updateProducts

I may be missing something very naive! Could anybody suggest the cause of
the error?

I have given you a hint with my snippage :)
 
G

Guest

Hi Larry,

Changing the line of code you mentioned to:
command.Parameters.Add(New SqlParameter("@pMacId", SqlDbType.Char, 6))

still gives tbe same error that @pMacId is not a parameter to the stored
procedure.

kd

Larry Lard said:
Hi All,

I am trying to pass parameters to a stored procedure from vb.net code and
fails with the error that the variable is not a parameter to the stored
procedure

Here is the vb.net code [snips]
command.Parameters.Add(New SqlParameter("@pMacId",
SqlDbType.Char))
Here is the stored procedure code:
@pMachineId AS CHAR(6),
The error message occurs on ExecuteNonQuery() and says that @pMacId is not a
prameter to the stored procedure sp_updateProducts

I may be missing something very naive! Could anybody suggest the cause of
the error?

I have given you a hint with my snippage :)
 
C

Cor Ligthert

KD,
I am using SQLClient.
Exactly however as I wrote the OleDb method, I am not sure if that is the
source of your problem. However, in your case would I at least try it.

Cor
 
L

Larry Lard

kd said:
Hi Larry,

Changing the line of code you mentioned to:
command.Parameters.Add(New SqlParameter("@pMacId", SqlDbType.Char, 6))

still gives tbe same error that @pMacId is not a parameter to the stored
procedure.

Well it isn't :) The first parameter to the stored procedure is called
@pMachineId, not @pMacId
kd

Larry Lard said:
Hi All,

I am trying to pass parameters to a stored procedure from vb.net
code
and
fails with the error that the variable is not a parameter to the stored
procedure

Here is the vb.net code [snips]
command.Parameters.Add(New SqlParameter("@pMacId",
SqlDbType.Char))
Here is the stored procedure code:
@pMachineId AS CHAR(6),
The error message occurs on ExecuteNonQuery() and says that
@pMacId
is not a
prameter to the stored procedure sp_updateProducts

I may be missing something very naive! Could anybody suggest the cause of
the error?

I have given you a hint with my snippage :)
 
C

Cor Ligthert

Larry,

I saw it, looked at the code and thought, no that is the valuename when I
scrolled back in the message.

Stupid me.

:)

Cor
 
G

Guest

Hi Cor,

The example shown in the link passes values directly, instead of variables
as parameters. And in my case, the error occurs in the variable. Moreover, I
am executing the stored procedure in a transaction. If my understanding is
correct, using Fill would close the connection (when Datasets are used). I
want the transaction to be live even after executing the procedure.

kd
 

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