Пример #1
0
        /// <summary>
        /// ===== EXAMPLE METHOD 2 ============
        /// </summary>
        /// This method is to be used to return a list of employee information.
        /// <returns>
        ///  A list of employee information
        /// </returns>
        public List <SampleEmployeeDataModel> GetCodeSampleList()
        {
            List <SampleEmployeeDataModel> SampleDataModel = new List <SampleEmployeeDataModel>();

            SqlConnection SQLconn = new SqlConnection();
            SqlCommand    SQLcomm = new SqlCommand();
            SqlDataReader SQLRec;

            //connection string to the database
            SQLconn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["EmployeeDataBaseConnectionString"].ConnectionString;

            //open connection
            SQLconn.Open();

            //stored procedure name
            string SQL = "ssp_tblEmployee_GetEmployeeInformationList";

            SQLcomm             = new SqlCommand(SQL, SQLconn);
            SQLcomm.CommandType = CommandType.StoredProcedure;

            SQLRec = SQLcomm.ExecuteReader();

            //read data into the model
            while (SQLRec.Read())
            {
                SampleDataModel.Add(new SampleEmployeeDataModel
                {
                    ID        = SQLRec.GetInt32(SQLRec.GetOrdinal("ID")),
                    FirstName = SQLRec.GetString(SQLRec.GetOrdinal("FirstName")),
                    LastName  = SQLRec.GetString(SQLRec.GetOrdinal("LastName")),
                    DOB       = SQLRec.GetDateTime(SQLRec.GetOrdinal("DOB")),
                    SSN       = SQLRec.GetString(SQLRec.GetOrdinal("SSN")),
                });
            }

            //close connection
            SQLRec.Close();
            SQLconn.Close();

            return(SampleDataModel);
        }