void Button1Click(object sender, EventArgs e)
        {
            Koneksi sambung = new Koneksi();

            try{
                sambung.buka();
                MessageBox.Show("Berhasil Koneksi Database", "Konfirmasi");
                this.Hide();
                FormOperationDML tampil = new FormOperationDML();
                tampil.ShowDialog();
            }
            catch (MySqlException ex)
            {
                switch (ex.Number)
                {
                case 0:
                { MessageBox.Show("Koneksi Gagal", "Konfirmasi"); }
                break;

                case 1045:
                { MessageBox.Show("Username atau Password Salah", "Konfirmasi"); }
                break;
                }
            }
        }
Beispiel #2
0
        void HapusClick(object sender, EventArgs e)
        {
            sambung = new Koneksi();
            sql     = "DELETE FROM mahasiswa where stb='" + stb.Text + "' ";

            try{
                sambung.buka();
                query   = new MySqlCommand(sql, sambung.koneksi);
                adapter = new MySqlDataAdapter(query);
                query.ExecuteNonQuery();
                MessageBox.Show("Data Berhasil Dihapus !!", "information");
                bersihkan();
                TampilDalamTable();
            } catch (Exception er) {
                MessageBox.Show(er.Message);
            }
            sambung.tutup();
        }
        public DataTable bacasemua()
        {
            sambung = new Koneksi();
            sql     = "Select * From Mahasiswa";
            tabel   = new DataTable();

            try {
                sambung.buka();
                query   = new MySqlCommand(sql, sambung.koneksi);
                adapter = new MySqlDataAdapter(query);
                query.ExecuteNonQuery();
                adapter.Fill(tabel);
            } catch (Exception er) {
                MessageBox.Show(er.Message);
            }
            sambung.tutup();
            return(tabel);
        }
        public DataTable tampilpencarian(string cari)
        {
            sambung = new Koneksi();
            sql     = "SELECT * FROM mahasiswa where nama LIKE '%" + cari + "%'";
            tabel   = new DataTable();

            try {
                sambung.buka();
                query   = new MySqlCommand(sql, sambung.koneksi);
                adapter = new MySqlDataAdapter(query);
                query.ExecuteNonQuery();
                adapter.Fill(tabel);
            } catch (Exception er) {
                MessageBox.Show(er.Message);
            }
            sambung.tutup();
            return(tabel);
        }
Beispiel #5
0
 void EditClick(object sender, EventArgs e)
 {
     sambung = new Koneksi();
     sql     = "UPDATE mahasiswa SET nama ='" + nama.Text + "', alamat ='" + alamat.Text + "', " +
               "nilai_tugas=" + nt.Value + ", nilai_mid=" + nm.Value + ", " +
               "nilai_final=" + nf.Value + ", nilai_akhir='" + na.Text + "', nilai_huruf='" + nh.Text + "', " +
               "keterangan='" + keterangan.Text + "' where stb='" + stb.Text + "' ";
     try {
         sambung.buka();
         query   = new MySqlCommand(sql, sambung.koneksi);
         adapter = new MySqlDataAdapter(query);
         query.ExecuteNonQuery();
         MessageBox.Show("Data Berhasil Diubah !!", "information");
         TampilDalamTable();
     } catch (Exception er) {
         MessageBox.Show(er.Message);
     }
     sambung.tutup();
 }
Beispiel #6
0
        void StbKeyPress(object sender, KeyPressEventArgs e)
        {
            sambung = new Koneksi();
            if (e.KeyChar == (char)Keys.Enter)
            {
                sql = "SELECT * FROM mahasiswa where stb='" + stb.Text + "' ";
                try{
                    sambung.buka();
                    query   = new MySqlCommand(sql, sambung.koneksi);
                    adapter = new MySqlDataAdapter(query);
                    //				dr = new MySqlDataReader();
                    dr = query.ExecuteReader();


                    if (dr.Read())
                    {
                        MessageBox.Show("Data Sudah Ada", "information");
                        simpan.Enabled  = false;
                        edit.Enabled    = true;
                        hapus.Enabled   = true;
                        nama.Text       = dr[2].ToString();
                        alamat.Text     = dr[3].ToString();
                        nt.Value        = Convert.ToInt32(dr[4]);
                        nm.Value        = Convert.ToInt32(dr[5]);
                        nf.Value        = Convert.ToInt32(dr[6]);
                        na.Text         = dr[7].ToString();
                        nh.Text         = dr[8].ToString();
                        keterangan.Text = dr[9].ToString();
                    }
                    else
                    {
                        simpan.Enabled = true;
                        nama.Select();
                    }
                    sambung.tutup();
                } catch (Exception er) {
                    MessageBox.Show(er.Message);
                }
            }
        }
Beispiel #7
0
        void SimpanClick(object sender, EventArgs e)
        {
            sambung = new Koneksi();

            sql = "INSERT INTO mahasiswa (stb, nama, alamat, nilai_tugas, nilai_mid, nilai_final, nilai_akhir, " +
                  "nilai_huruf, keterangan) " +
                  "VALUES ('" + stb.Text + "', '" + nama.Text + "', '" + alamat.Text + "', " + nt.Value + ", " + nm.Value + ", " + nf.Value + ", '" + na.Text + "', '" + nh.Text + "', " +
                  "'" + keterangan.Text + "')";

            try{
                sambung.buka();
                query   = new MySqlCommand(sql, sambung.koneksi);
                adapter = new MySqlDataAdapter(query);
                query.ExecuteNonQuery();
                MessageBox.Show("Data Berhasil Disimpan !!", "information");
                bersihkan();
                TampilDalamTable();
            } catch (Exception er) {
                MessageBox.Show(er.Message);
            }
            sambung.tutup();
        }