Example #1
0
 /// <summary>
 /// Creates an instance of Student from the data record in the database.
 /// </summary>
 /// <param name="myRecord">Single row of record.</param>
 /// <returns>A student</returns>
 private static Student FillRecord(IDataRecord myRecord)
 {
     Student myStudent = new Student();
     myStudent.SId = myRecord.GetString(myRecord.GetOrdinal("SID"));
     myStudent.Password = myRecord.GetString(myRecord.GetOrdinal("Password"));
     myStudent.FName = myRecord.GetString(myRecord.GetOrdinal("Fname"));
     if (!myRecord.IsDBNull(myRecord.GetOrdinal("MI")))
     {
         myStudent.MI = myRecord.GetString(myRecord.GetOrdinal("MI"));
     }
     myStudent.LName = myRecord.GetString(myRecord.GetOrdinal("Lname"));
     myStudent.Street = myRecord.GetString(myRecord.GetOrdinal("Street"));
     myStudent.City = myRecord.GetString(myRecord.GetOrdinal("City"));
     myStudent.State = myRecord.GetString(myRecord.GetOrdinal("State"));
     myStudent.Zipcode = myRecord.GetString(myRecord.GetOrdinal("Zipcode"));
     return myStudent;
 }
Example #2
0
 public static int Save(Student myStudent)
 {
     return StudentDA.Save(myStudent);
 }
Example #3
0
        /// <summary>
        /// Saves a student in the database.
        /// </summary>
        /// <param name="myStudent">The student to store.</param>
        /// <returns>The new ID if the student is new in the database or the existing ID when an record was updated.</returns>
        public static int Save(Student myStudent)
        {
            int result = 0;
            using (SqlConnection myConnection = new SqlConnection(AppSettings.ConnectionString))
            {
                SqlCommand myCommand = new SqlCommand("spSaveStudent",myConnection);
                myCommand.CommandType = CommandType.StoredProcedure;
                myCommand.Parameters.AddWithValue("@SID", myStudent.SId);
                myCommand.Parameters.AddWithValue("@Password", myStudent.Password);
                myCommand.Parameters.AddWithValue("@FName", myStudent.FName);
                if (String.IsNullOrEmpty(myStudent.MI))
                {
                    myCommand.Parameters.AddWithValue("@MI", DBNull.Value);
                }
                else
                {
                    myCommand.Parameters.AddWithValue("@MI", myStudent.MI);
                }
                myCommand.Parameters.AddWithValue("@LName", myStudent.LName);
                myCommand.Parameters.AddWithValue("@Street", myStudent.Street);
                myCommand.Parameters.AddWithValue("@City", myStudent.City);
                myCommand.Parameters.AddWithValue("@State", myStudent.State);
                myCommand.Parameters.AddWithValue("@Zipcode", myStudent.Zipcode);

                DbParameter retValue = myCommand.CreateParameter();
                retValue.Direction = ParameterDirection.ReturnValue;
                myCommand.Parameters.Add(retValue);

                myConnection.Open();
                myCommand.ExecuteNonQuery();
                result = Convert.ToInt32(retValue.Value);
                myConnection.Close();
            }
            return result;
        }