473,387 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

SQL Parameter question

I am writing some code that passes two parameters to a store procedure. One
of the parameters is an output parameter. I am querying the DB using the
input value and returning a field from the result using the output parameter.
The issue is that when I run the ExecuteNonquery command I get the following
error:

'@shortLinkUrl' of type: String, the property Size has an invalid size: 0
Any ideas? Please help. I am a beginner programmer using C# and ASP.NET, so
please be as detailed as possible in your help. Thanks.

Hector
Nov 19 '05 #1
6 1185
Did you add it as an output parameter to the parameters collection of
the command you are executing? You can do so by setting the parameter's
Direction to ParameterDirection.Output.

----
- Wilco Bauwer
Blog & Custom Controls @ http://wilcoding.xs4all.nl

Nov 19 '05 #2
First of all, thank you for answering my query. To answer your question, yes
I did add it to the command object as an output parameter. I also coded the
T-SQL of the store procedure as an output parameter. I genuinely believed I
did everything I had to do to ensure everything works as it's supposed to. I
even had similar code, that works the same way, that works fine. I compared
the code to make sure I did not make any mistakes along the way and
everything seems fine. Here is some sample code that I am using:
SqlParameter[] Parameters;
Parameters = new SqlParameter[2];
Parameters[0] = new SqlParameter("@shortLinkId", SqlDbType.VarChar);
Parameters[0].Value = shortLinkId;
Parameters[1] = new SqlParameter("@shortLinkUrl", SqlDbType.VarChar);
Parameters[1].Direction = ParameterDirection.Output;
SqlHelper.ExecuteCommand(connectionString, "spGetShortLinkUrl", Parameters);
shortLinkUrl = Parameters[1].Value.ToString();
The following is some code from the ExecuteCommand method:

SqlCommand Command = new SqlCommand();
Command.Connection = new SqlConnection(connection);
Command.CommandText = commandText;
Command.CommandType = commandType;
foreach (SqlParameter parameter in commandParameters)
Command.Parameters.Add(parameter);

Command.Connection.Open();
int recordsAffected;
try
{
recordsAffected = Command.ExecuteNonQuery();
}
catch (Exception ex)
..
..
..
Thanks,
Hector

"Wilco Bauwer" wrote:
Did you add it as an output parameter to the parameters collection of
the command you are executing? You can do so by setting the parameter's
Direction to ParameterDirection.Output.

----
- Wilco Bauwer
Blog & Custom Controls @ http://wilcoding.xs4all.nl

Nov 19 '05 #3
Ok. Did you try to specify the length parameter (check the overloads
for the SqlParameter constructor)? If not, try to set it to the length
you specified in your stored procedure.

----
- Wilco Bauwer
Blog & Custom Controls @ http://wilcoding.xs4all.nl

Nov 19 '05 #4
It's very weird. I have code that works the same way as the one I am having
problems with, but your suggestion did the trick. The code works fine now.
Thank you.

Hector

"Wilco Bauwer" wrote:
Ok. Did you try to specify the length parameter (check the overloads
for the SqlParameter constructor)? If not, try to set it to the length
you specified in your stored procedure.

----
- Wilco Bauwer
Blog & Custom Controls @ http://wilcoding.xs4all.nl

Nov 19 '05 #5
I came across the same issue as well. Its strange how the exact code works
in one situtation and then don't work in the other

"hecsan07" <he******@hotmail.com> wrote in message
news:A9**********************************@microsof t.com...
It's very weird. I have code that works the same way as the one I am
having
problems with, but your suggestion did the trick. The code works fine now.
Thank you.

Hector

"Wilco Bauwer" wrote:
Ok. Did you try to specify the length parameter (check the overloads
for the SqlParameter constructor)? If not, try to set it to the length
you specified in your stored procedure.

----
- Wilco Bauwer
Blog & Custom Controls @ http://wilcoding.xs4all.nl

Nov 19 '05 #6
Thats true ..i had similar occasions too.
Patrick

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: WGW | last post by:
Though I am a novice to MS SQL server (2000 I believe), I can do almost! everything I need. Maybe not efficiently, but usefully. However, I have a problem -- a complex query problem... I can...
1
by: Prashanth | last post by:
Hi , I want to make a stored proc call thru .NET . I use the SqlParameter objects to create input parameters and set it's value. SqlParameter myParameter = new...
3
by: Aguilar, James | last post by:
Hey all. I was making a newbie mistake that I eventually figured out. That is not my question. My question is about the error message. So let me set the stage for you: class Superclass {...
3
by: thomas goodwin | last post by:
I have a query which asks for a parameter value to execute it. To see the results I have to: a) click on the query -- the "Enter Parameter Value" window pops up. b) enter the parameter value c)...
7
by: Britney | last post by:
Original code: this.oleDbSelectCommand1.CommandText = "SELECT TOP 100 user_id, password, nick_name, sex, age, has_picture, city, state, " + "country FROM dbo.users WHERE (has_picture = ?) AND (sex...
12
by: Darwin Lalo | last post by:
I have a lot of code like this: VOID CALLBACK TimerRoutine(PVOID lpParam) { long nTaskid = (long)lpParam; GObj *obj; if( mapThreadSafe.find( nTaskid, obj )) // mapThreadSafe is a hash_map,...
16
by: hzmonte | last post by:
Correct me if I am wrong, declaring formal parameters of functions as const, if they should not be/is not changed, has 2 benefits; 1. It tells the program that calls this function that the...
4
by: David Sanders | last post by:
Hi, I have a class with an integer template parameter, taking values 1, 2 or 3, and a function 'calc' in that class which performs calculations. Some calculations need only be performed if the...
6
by: HillBilly | last post by:
One question I have not figured out is how to learn which event parameter list is supported by a control? EventArgs, CommandEventArgs, what?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.