コード例 #1
0
        public void LoadByWord(ICollection <wordsObject> collection, string word)
        {
            string sql = "select * from words where word=@word";

            using (MySqlConnection conn = new MySqlConnection(constr))
            {
                try
                {
                    conn.Open();

                    using (MySqlCommand cmd = new MySqlCommand(sql, conn))
                        using (MySqlDataReader row = cmd.ExecuteReader())
                        {
                            cmd.Parameters.AddWithValue("@word", word);
                            while (row.Read())
                            {
                                wordsObject w = new wordsObject(row);
                                collection.Add(w);
                            }
                        }
                }
                catch (MySqlException e)
                {
                    throw;
                }
            }
        }
コード例 #2
0
        public void Load(ICollection <wordsObject> collection)
        {
            string sql = "select * from words ";

            using (MySqlConnection conn = new MySqlConnection(constr))
            {
                try
                {
                    conn.Open();

                    using (MySqlCommand cmd = new MySqlCommand(sql, conn))
                        using (MySqlDataReader row = cmd.ExecuteReader())
                        {
                            while (row.Read())
                            {
                                wordsObject w = new wordsObject(row);
                                collection.Add(w);
                            }
                        }
                }
                catch (MySqlException e)
                {
                    throw;
                }
            }
        }