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