Пример #1
0
        public Meaning findById(int id)
        {
            try
            {
                Program.conn.Open();    // Open new connection
                SQLiteCommand    cmd     = new SQLiteCommand("SELECT * FROM meaning WHERE id = " + id, Program.conn);
                SQLiteDataReader reader  = cmd.ExecuteReader();
                Meaning          meaning = new Meaning();
                IWordDAO         wordDao = new WordDAO();

                while (reader.Read())
                {
                    meaning = new Meaning(reader.GetInt32(0), reader.GetString(2), wordDao.findById(reader.GetInt32(1)));
                }

                return(meaning);
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0} Exception caught.", ex);
                return(null);
            }
            finally
            {
                Program.conn.Close();   // Close connection
            }
        }
Пример #2
0
        public ObservableCollection <Meaning> getAll()
        {
            IWordDAO wordDao = new WordDAO();
            ObservableCollection <Meaning> meanings = new ObservableCollection <Meaning>();

            try
            {
                Program.conn.Open();    // Open new connection
                SQLiteCommand    cmd    = new SQLiteCommand("SELECT * FROM meaning", Program.conn);
                SQLiteDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    meanings.Add(new Meaning(reader.GetInt32(0), reader.GetString(2), wordDao.findById(reader.GetInt32(1))));
                }

                return(meanings);
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0} Exception caught.", ex);
                return(null);
            }
            finally
            {
                Program.conn.Close();   // Close connection
            }
        }