473,796 Members | 2,483 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1201
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 ParameterDirect ion.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.VarCh ar);
Parameters[0].Value = shortLinkId;
Parameters[1] = new SqlParameter("@ shortLinkUrl", SqlDbType.VarCh ar);
Parameters[1].Direction = ParameterDirect ion.Output;
SqlHelper.Execu teCommand(conne ctionString, "spGetShortLink Url", Parameters);
shortLinkUrl = Parameters[1].Value.ToString ();
The following is some code from the ExecuteCommand method:

SqlCommand Command = new SqlCommand();
Command.Connect ion = new SqlConnection(c onnection);
Command.Command Text = commandText;
Command.Command Type = commandType;
foreach (SqlParameter parameter in commandParamete rs)
Command.Paramet ers.Add(paramet er);

Command.Connect ion.Open();
int recordsAffected ;
try
{
recordsAffected = Command.Execute NonQuery();
}
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 ParameterDirect ion.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******@hotma il.com> wrote in message
news:A9******** *************** ***********@mic rosoft.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
16947
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 create a parameter query in a stored procedure, but how do I use the result set of a parameter query in a select query (in the same or another sp)? In short, if a select query contains a result table that is generated as a parameter query, how do I...
1
1771
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 SqlParameter("@Description",SqlDbType.VarChar); myParameter.Value = "some string size not known. but max size of the string can be only 1024 characters"; Note : I have not mentioned the size of the parameter using
3
9484
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 { public: Superclass(int); }
3
3129
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) look at results in datasheet view If I want to run the query again, I must d) click to close the datasheet view e) click on the query f) enter the parameter value
7
3045
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 = ?) ORDER BY age " this.oleDbSelectCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("has_picture", System.Data.OleDb.OleDbType.Boolean, 1, "has_picture")); this.oleDbSelectCommand1.Parameters.Add(new...
12
3683
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, thread safe {
16
3167
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 parameter will not be changed - so don't worry. 2. It tells the implementor and the maintainer of this function that the parameter should not be changed inside the function. And it is for this reason that some people advocate that it is a good idea to...
4
3015
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 template parameter is 2 or 3; for efficiency, I do not wish to perform the calculations if the template parameter is 1. I currently do this as follows:
6
1444
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
10455
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10228
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10006
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7547
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.