Esempio n. 1
0
        /// <summary>
        /// Scalar Value: illustrates how to retrieve scalar (single value) data from database.
        /// </summary>
        /// <param name="employeeId"></param>
        /// <returns></returns>
        ///Utils.GenerationCommandType.ScalarValue
        public static string GetFirstNameByEmployeeId(int employeeId)
        {
            if (employeeId < GetIdMinValue)
            {
                throw (new ArgumentOutOfRangeException("employeeId"));
            }

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();

            DatabaseUtility.AddParameterToSqlCmd(sqlCmd, "@employeeId", SqlDbType.Int, 0, ParameterDirection.Input, employeeId);
            DatabaseUtility.AddParameterToSqlCmd(sqlCmd, "@ReturnVal", SqlDbType.NVarChar, 10, ParameterDirection.Output, null);
            DatabaseUtility.SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_CUSTOM_EMPLOYEES_GETEMPLOYEEFIRSTNAME_BY_EMPLOYEEID);

            //executing the command
            DatabaseUtility.ExecuteScalarCmd(sqlCmd);

            string returnValue = (string)sqlCmd.Parameters["@ReturnVal"].Value;

            return(returnValue);
        }