Home All Groups Group Topic Archive Search About

Passing Variable as parameters

Author
24 Sep 2005 10:20 AM
free70@community.nospam
I am trying to pass two parameters to a stored procedure that works fine when
I use the code, for example:

param_user.Value = "blahblah@com"

The problem is the value I need is in a variable, but when I use:

param_user.Value = variable name

I get no records returned.

I cant seem to be able to pass the variable into the param.value...any ideas?

Thanks in advance

Author
24 Sep 2005 10:31 AM
David Portas
One common error is to fail to declare the size of character values in your
parameter declaration. If you declare a parameter as CHAR, VARCHAR, NCHAR or
NVARCHAR without specifying a maximum size then 1 is the default and the
value you pass will be truncated.

If that's not it then please post some runnable code to reproduce the
problem.

--
David Portas
SQL Server MVP
--
Author
26 Sep 2005 12:15 PM
free70@community.nospam
Thanks David,
I think I am declaring the parameter correctly...

Dim param_user As New SqlParameter("@u", SqlDbType.NVarChar, 40)

I then assign a variable to the parameters value...

param_user.Value = uname

and then add it to the command object before I execute...

command.Parameters.Add(param_user)

I have tested the variable(uname)and it has the values I want to send and
that seems fine.

If I replace the line...

param_user.Value = uname with param_user.Value = "sometext" it works fine.

For your information this code takes place in a data access class I have
written which is called from an ASPX file which sends a users login details.

Thanks in advance

Geoff



Show quote
"David Portas" wrote:

> One common error is to fail to declare the size of character values in your
> parameter declaration. If you declare a parameter as CHAR, VARCHAR, NCHAR or
> NVARCHAR without specifying a maximum size then 1 is the default and the
> value you pass will be truncated.
>
> If that's not it then please post some runnable code to reproduce the
> problem.
>
> --
> David Portas
> SQL Server MVP
> --
>
>
>
Author
24 Sep 2005 2:32 PM
John Bell
Hi

In addition to Davids information, you can see what is being sent to SQL
Server by using SQL Profiler. Check out books online for more information
about this utility.

John

Show quote
"free70@community.nospam" <free70communitynospam@discussions.microsoft.com>
wrote in message news:B6218A5B-7279-4879-BFCC-FE6CF7E778F4@microsoft.com...
>I am trying to pass two parameters to a stored procedure that works fine
>when
> I use the code, for example:
>
> param_user.Value = "blahblah@com"
>
> The problem is the value I need is in a variable, but when I use:
>
> param_user.Value = variable name
>
> I get no records returned.
>
> I cant seem to be able to pass the variable into the param.value...any
> ideas?
>
> Thanks in advance

AddThis Social Bookmark Button