Error about outgoing parameters in Stored Procedure

Source: Internet
Author: User

-- Function Description: returns the nickname of the current user.
-- Creator: suney
-- Date: 2008-03-25
Alter procedure door_networkdoorplate_getuserinfo
@ Doorid int,
@ Username nvarchar (50) Output
As
Begin try
Select @ username = username from db_networkdoorplate where doorplateid = @ doorid
Return @ username
End try
Begin catch
Return @ username

End catch
The returned value of this stored procedure is of the string type,

# region: Obtain the nickname of a user
///


// obtain the nickname of a user
///
/// id
///
Public static string GetUserName (INT doorid)
{< br> try
{< br> sqlparameter [] parameters = new sqlparameter [2];
parameters [0] = new sqlparameter ("@ doorid", doorid);
parameters [1] = new sqlparameter ("@ username", sqldbtype. nvarchar, 50);

//The size attribute has an invalid size value: 0 this error occurs if the size of the outgoing parameter of the string type is not specified, but it is not required if it is an int type,

Parameters [1]. Direction = parameterdirection. output;

Sqlhelper. executenonquery (sqlhelper. doorconnectionstring, commandtype. storedprocedure, "door_networkdoorplate_getuserinfo", parameters );

String temp = NULL;

Temp = parameters [1]. value. tostring ();

If (temp! = NULL)
{< br> return temp;
}< br> else
{< br> return NULL;
}< BR >}< br> catch (system. exception e)
{< br> throw E;
}< BR >}

# Endregion

To sum up the reason: the input parameter can be directly given without specifying the length, but the length must be specified for outgoing parameters.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.