What am I doing worng...?

B

Bruno Alexandre

Hi guys....


I must be doing something wrong, but What?

This code works fine:
--------------------------------------
strSQL = "SELECT * FROM utiUtentes WHERE idUtente = " & idUtente
With cmd
..Connection = conn
..CommandText = strSQL
..CommandType = CommandType.Text
End With

conn.Open()
------------------------------------------------

this won't!
------------------------------------------------
strSQL = "spGetUser"

With cmd
..Connection = conn
..CommandText = strSQL
..CommandType = CommandType.StoredProcedure
..Parameters("@idUser").Value = idUtente
End With

conn.Open()
-----------------------------------------------

the spGetUser store Procedure is this:

ALTER PROCEDURE [spGetUser]
@idUser as numeric
AS (
SELECT * FROM utiUsers WHERE idUser = @idUser
)

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

the variable idUser in VB code is a string type.


--



Bruno Alexandre
(Sintra, PORTUGAL)
 
F

Frans Bouma [C# MVP]

Bruno said:
Hi guys....


I must be doing something wrong, but What?

This code works fine:
--------------------------------------
strSQL = "SELECT * FROM utiUtentes WHERE idUtente = " & idUtente
With cmd
.Connection = conn
.CommandText = strSQL
.CommandType = CommandType.Text
End With

conn.Open()
------------------------------------------------

this won't!
------------------------------------------------
strSQL = "spGetUser"

With cmd
.Connection = conn
.CommandText = strSQL
.CommandType = CommandType.StoredProcedure
.Parameters("@idUser").Value = idUtente
End With

conn.Open()
-----------------------------------------------

the spGetUser store Procedure is this:

ALTER PROCEDURE [spGetUser]
@idUser as numeric
AS (
SELECT * FROM utiUsers WHERE idUser = @idUser
)

in that case, change
@idUser as numeric

into

@idUser as varchar(100)

Frans

ps: use parameters in dynamic sql as well.



--
 
B

Bruno Alexandre

even so...

the error message is the same:
"An SqlParameter with ParameterName '@idUser' is not contained by this
SqlParameterCollection"

:(

what's worng with VS? the @idUser is in the SP, if I use this sp in the
Query Analyser it works!

--



Bruno Alexandre
(Sintra, PORTUGAL)



Frans Bouma said:
Bruno said:
Hi guys....


I must be doing something wrong, but What?

This code works fine:
--------------------------------------
strSQL = "SELECT * FROM utiUtentes WHERE idUtente = " & idUtente
With cmd
.Connection = conn
.CommandText = strSQL
.CommandType = CommandType.Text
End With

conn.Open()
------------------------------------------------

this won't!
------------------------------------------------
strSQL = "spGetUser"

With cmd
.Connection = conn
.CommandText = strSQL
.CommandType = CommandType.StoredProcedure
.Parameters("@idUser").Value = idUtente
End With

conn.Open()
-----------------------------------------------

the spGetUser store Procedure is this:

ALTER PROCEDURE [spGetUser]
@idUser as numeric
AS (
SELECT * FROM utiUsers WHERE idUser = @idUser
)

in that case, change
@idUser as numeric

into

@idUser as varchar(100)

Frans

ps: use parameters in dynamic sql as well.



--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
B

Bruno Alexandre

just changing this
..Parameters.("@idUtente").Add = idUtente


into this
..Parameters.AddWithValue("@idUtente", idUtente)


Thank you Cor
--



Bruno Alexandre
(Sintra, PORTUGAL)
 

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