--功能描述:返回当前的用户的昵称
--创建者:SunEy
--日期: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
此存储过程返回值是string类型的,
#region 获取用户的昵称
/// <summary>
/// 获取用户的昵称
/// </summary>
/// <param name="DoorID">ID</param>
/// <returns></returns>
public static string GetUserName(int DoorID)
{
try
{
SqlParameter[] parameters = new SqlParameter[2];
parameters[0] = new SqlParameter("@DoorID", DoorID);
parameters[1] = new SqlParameter("@UserName", SqlDbType.NVarChar,50);
//Size 属性具有无效大小值: 0 如果不指定string类型的传出参数的size就会出现此错误,但是如果是int类型的就不需要,
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)
{
return Temp;
}
else
{
return null;
}
}
catch (System.Exception e)
{
throw e;
}
}
#endregion
总结原因:传入参数可以不指定长度,直接给值,但传出的必须指定长度