Esempio n. 1
0
        public DataTable GetAll()
        {
            string  query = "SELECT nis,nama,kelas FROM siswa";
            MySQLDB db    = new MySQLDB();

            return(db.GetData(query));
        }
Esempio n. 2
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 + "%" }
            }));
        }
Esempio n. 3
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);
        }