Esempio n. 1
0
 /// <summary>
 /// Creates an instance of Department from the data record in the database.
 /// </summary>
 /// <param name="myRecord">Single row of record.</param>
 /// <returns>An Department.</returns>
 private static Department FillRecord(IDataRecord myRecord)
 {
     Department myDepartment = new Department();
     myDepartment.DNo = myRecord.GetInt32(myRecord.GetOrdinal("DNo"));
     myDepartment.DName = myRecord.GetString(myRecord.GetOrdinal("DName"));
     myDepartment.DLocation = myRecord.GetString(myRecord.GetOrdinal("DLocation"));
     return myDepartment;
 }
Esempio n. 2
0
        /// <summary>
        /// Saves an Department in the database.
        /// </summary>
        /// <param name="myDepartment">The Department to store.</param>
        /// <returns>The new Department id if the Department is new in the database or the existing ID when an record was updated.</returns>
        public static int Save(Department myDepartment)
        {
            int result = 0;
            using (SqlConnection myConnection = new SqlConnection(AppSettings.ConnectionString))
            {
                SqlCommand myCommand = new SqlCommand("spSaveDepartment", myConnection);
                myCommand.CommandType = CommandType.StoredProcedure;
                myCommand.Parameters.AddWithValue("@DNo", myDepartment.DNo);
                myCommand.Parameters.AddWithValue("@DName", myDepartment.DName);
                myCommand.Parameters.AddWithValue("@DLocation", myDepartment.DLocation);

                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;
        }