예제 #1
0
        public DataTable GetAll()
        {
            string  query = "SELECT nis,nama,kelas FROM siswa";
            MySQLDB db    = new MySQLDB();

            return(db.GetData(query));
        }
예제 #2
0
        public void Hapus(string nis)
        {
            string  query = "DELETE FROM siswa WHERE nis=@kriteria";
            MySQLDB db    = new MySQLDB();

            db.Execute(query, new Dictionary <string, dynamic>()
            {
                { "@kriteria", nis }
            });
        }
예제 #3
0
        public DataTable GetByName(string nama)
        {
            string  query = "SELECT nis,nama,kelas FROM siswa WHERE nama LIKE @kriteria";
            MySQLDB db    = new MySQLDB();

            return(db.GetData(query, new Dictionary <string, dynamic>()
            {
                { "@kriteria", "%" + nama + "%" }
            }));
        }
예제 #4
0
        public void Add(SiswaModel data)
        {
            string  query = "INSERT INTO siswa (nis,nama,kelas) VALUES (@nis,@nama,@kelas)";
            MySQLDB db    = new MySQLDB();

            db.Execute(query, new Dictionary <string, dynamic>()
            {
                { "@nis", data.nis },
                { "@nama", data.nama },
                { "@kelas", data.kelas }
            });
        }
예제 #5
0
        public void Edit(string nis, SiswaModel data)
        {
            string  query = "UPDATE siswa SET nis=@nisBaru,nama=@namaBaru,kelas=@kelasBaru WHERE nis=@nisLama";
            MySQLDB db    = new MySQLDB();

            db.Execute(query, new Dictionary <string, dynamic>()
            {
                { "@nisBaru", data.nis },
                { "@namaBaru", data.nama },
                { "@kelasBaru", data.kelas },
                { "@nisLama", nis }
            });
        }
예제 #6
0
        public SiswaModel GetByNis(string nis)
        {
            SiswaModel data    = null;
            string     query   = "SELECT nis,nama,kelas FROM siswa WHERE nis=@kriteria";
            MySQLDB    db      = new MySQLDB();
            DataTable  dtSiswa = db.GetData(query, new Dictionary <string, dynamic>()
            {
                { "@kriteria", nis }
            });

            if (dtSiswa.Rows.Count == 1)
            {
                //ambil satu baris saja
                DataRow row = dtSiswa.Rows[0];
                //masukkan ke model siswa
                data       = new SiswaModel();
                data.nis   = row["nis"].ToString();
                data.nama  = row["nama"].ToString();
                data.kelas = row["kelas"].ToString();
            }

            return(data);
        }