PC Review


Reply
Thread Tools Rate Thread

What am I doing worng...?

 
 
Bruno Alexandre
Guest
Posts: n/a
 
      15th Nov 2005
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)





 
Reply With Quote
 
 
 
 
Frans Bouma [C# MVP]
Guest
Posts: n/a
 
      15th Nov 2005
Bruno Alexandre wrote:

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


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#)
------------------------------------------------------------------------
 
Reply With Quote
 
Bruno Alexandre
Guest
Posts: n/a
 
      15th Nov 2005
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 [C# MVP]" <(E-Mail Removed)> escreveu na mensagem
news:(E-Mail Removed)...
> Bruno Alexandre wrote:
>
>> 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.

>
> 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#)
> ------------------------------------------------------------------------



 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      15th Nov 2005
Bruno,

You have to add that parameter to the collection first, that can in one
statement or in more, here a very simple sample.

http://www.vb-tips.com/default.aspx?...6-7139b8970071

Be aware that you only add it once and after that set it as you do.

This is 2002/2003 in VB2005 it works however it is changed in
AddWithValue

I hope this helps,

Cor


 
Reply With Quote
 
Bruno Alexandre
Guest
Posts: n/a
 
      15th Nov 2005
just changing this
..Parameters.("@idUtente").Add = idUtente


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


Thank you Cor
--



Bruno Alexandre
(Sintra, PORTUGAL)



"Cor Ligthert [MVP]" <(E-Mail Removed)> escreveu na mensagem
news:(E-Mail Removed)...
> Bruno,
>
> You have to add that parameter to the collection first, that can in one
> statement or in more, here a very simple sample.
>
> http://www.vb-tips.com/default.aspx?...6-7139b8970071
>
> Be aware that you only add it once and after that set it as you do.
>
> This is 2002/2003 in VB2005 it works however it is changed in
> AddWithValue
>
> I hope this helps,
>
> Cor
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is worng with this code? jlclyde Microsoft Excel Misc 3 27th Aug 2008 08:48 PM
What is worng with my formula? =?Utf-8?B?cm9iZXJ0IG1vcnJpcw==?= Microsoft Excel Misc 21 28th Aug 2007 10:47 PM
Anyone spot what's worng here? JethroUK© Microsoft Access Form Coding 2 1st May 2006 08:44 PM
what is worng with this JScript Craig G Microsoft ASP .NET 1 21st Dec 2004 11:23 AM
WHAT THE HELL IS WORNG WITH I.E.???? NedFowler Windows XP Internet Explorer 8 10th Oct 2004 01:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:31 AM.