コード例 #1
0
        private void LoadDB()
        {
            string strConn = "Data Source=" + Application.StartupPath + "\\data.db";

            if (!System.IO.File.Exists("data.db"))
            {
                MessageBox.Show("데이터베이스 파일 \"data.db\"를 찾을 수 없습니다.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
                return;
            }
            var              conn   = new SQLiteConnection(strConn).OpenAndReturn();
            string           sql    = "SELECT * FROM dolls";
            SQLiteCommand    cmd    = new SQLiteCommand(sql, conn);
            SQLiteDataReader reader = null;

            try
            {
                reader = cmd.ExecuteReader();
            }
            catch (SQLiteException)
            {
                MessageBox.Show("데이터베이스 파일 \"data.db\"가 유효하지 않습니다.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
                return;
            }
            while (reader.Read())
            {
                DollData.Add(new Doll
                {
                    Name    = (string)reader["name"],
                    Grade   = (int)reader["grade"],
                    Time    = (string)reader["time"],
                    Type    = (string)reader["type"],
                    IsHeavy = (bool)reader["isHeavy"]
                });
            }
            reader.Close();
            sql    = "SELECT * FROM equipments";
            cmd    = new SQLiteCommand(sql, conn);
            reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                EquipmentData.Add(new Equipment
                {
                    Name  = (string)reader["name"],
                    Grade = (int)reader["grade"],
                    Time  = (string)reader["time"],
                    Type  = (string)reader["type"],
                });
            }
            reader.Close();
            sql    = "SELECT * FROM fairies";
            cmd    = new SQLiteCommand(sql, conn);
            reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                FairyData.Add(new Fairy
                {
                    Name = (string)reader["name"],
                    Time = (string)reader["time"],
                    Type = (string)reader["type"],
                });
            }
            conn.Close();
        }