Ejemplo n.º 1
0
        /// <summary>
        /// Fills the <see cref="WordHolder"/> with all the data from database.
        /// </summary>
        public static void FillWordHolder(WordHolder wordHolder)
        {
            string sql = "SELECT * FROM words";

            try
            {
                using (SQLiteConnection cnt = new SQLiteConnection(dbPath))
                    using (SQLiteCommand cmd = new SQLiteCommand(sql, cnt))
                    {
                        cnt.Open();
                        using (SQLiteDataReader rdr = cmd.ExecuteReader())
                        {
                            while (rdr.Read())
                            {
                                wordHolder.Add(rdr.GetString(1), rdr.GetString(2), rdr.GetInt32(3));
                            }
                        }
                        cnt.Close();
                    }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Fills a <see cref="WordHolder"/> with data of CSV file.
 /// </summary>
 public static WordHolder ImportCsvToWordHolder(string path, bool isFirstRowHeader)
 {
     try
     {
         string     header     = isFirstRowHeader ? "Yes" : "No";
         string     pathOnly   = Path.GetDirectoryName(path);
         string     fileName   = Path.GetFileName(path);
         string     sql        = @"SELECT * FROM [" + fileName + "]";
         WordHolder wordHolder = new WordHolder();
         using (OleDbConnection cnt = new OleDbConnection(
                    @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathOnly +
                    ";Extended Properties=\"Text;HDR=" + header + "\""))
             using (OleDbCommand cmd = new OleDbCommand(sql, cnt))
                 using (OleDbDataAdapter adapter = new OleDbDataAdapter(cmd))
                 {
                     cnt.Open();
                     using (OleDbDataReader reader = cmd.ExecuteReader())
                     {
                         while (reader.Read())
                         {
                             wordHolder.Add(reader.GetString(0), reader.GetString(1), reader.GetInt32(2));
                         }
                     }
                     cnt.Close();
                 }
         return(wordHolder);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return(new WordHolder());
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Insert new rows to database from a CSV file.
        /// </summary>
        public static void ImportCsvToDatabase(string path, bool isFirstRowHeader)
        {
            WordHolder temp = ImportCsvToWordHolder(path, isFirstRowHeader);

            temp.InsertIntoDatabase();
        }