// btn delete private void buttonUpdate_Click(object sender, EventArgs e) { pelajar = new Pelajar(); gateway = new Gateway(); pelajar.Roll = textBoxRoll.Text; gateway.Delete(pelajar); MessageBox.Show("Deleted"); ResetField(); }
private void MasukanData() { Pelajar pelajar = new Pelajar(); pelajar.Roll = textBoxRoll.Text; pelajar.Bahasa = Convert.ToDecimal(textBoxBahasa.Text); pelajar.English = Convert.ToDecimal(textBoxEnglish.Text); pelajar.Science = Convert.ToDecimal(textBoxScience.Text); Gateway gateway = new Gateway(); gateway.SaveData(pelajar); MessageBox.Show("Saved"); ResetField(); }
public bool Delete(Pelajar pelajar) { string conn = "Data Source=DESKTOP-V5VOD86\\SQLEXPRESS;Initial Catalog=Universitas;Integrated Security=True"; SqlConnection sqlConnection = new SqlConnection(conn); sqlConnection.Open(); string query = @"DELETE FROM Mahasiswa WHERE Roll = " + pelajar.Roll; SqlCommand sqlCommand = new SqlCommand(query, sqlConnection); sqlCommand.ExecuteNonQuery(); sqlConnection.Close(); return(true); }
// button update private void button1_Click(object sender, EventArgs e) { Pelajar pelajar = new Pelajar(); Gateway gateway = new Gateway(); pelajar.Roll = textBoxRoll.Text; pelajar.Bahasa = Convert.ToDecimal(textBoxBahasa.Text); pelajar.English = Convert.ToDecimal(textBoxEnglish.Text); pelajar.Science = Convert.ToDecimal(textBoxScience.Text); gateway.Update(pelajar); MessageBox.Show("Updated"); ResetField(); }
private void buttonLihat_Click(object sender, EventArgs e) { pelajar = new Pelajar(); gateway = new Gateway(); pelajar = gateway.Get(textBoxRoll.Text); textBoxEnglish.Text = pelajar.English.ToString(); textBoxScience.Text = pelajar.Science.ToString(); textBoxBahasa.Text = pelajar.Bahasa.ToString(); buttonSimpan.Enabled = false; buttonDelete.Enabled = true; buttonUpdate.Enabled = true; }
public bool Update(Pelajar pelajar) { //pelajar = new Pelajar(); string conn = "Data Source=DESKTOP-V5VOD86\\SQLEXPRESS;Initial Catalog=Universitas;Integrated Security=True"; SqlConnection sqlConnection = new SqlConnection(conn); sqlConnection.Open(); string query = @"UPDATE Mahasiswa SET Bahasa = " + pelajar.English + ",English = " + pelajar.Bahasa + ", Science = " + pelajar.Science + "WHERE Roll = " + pelajar.Roll; SqlCommand sqlCommand = new SqlCommand(query, sqlConnection); sqlCommand.ExecuteNonQuery(); sqlConnection.Close(); return(true); }
public bool SaveData(Pelajar pelajar) { //string conn = "Data Source=DESKTOP-V5VOD86\\SQLEXPRESS;Initial Catalog=Universitas;Integrated Security=True"; //SqlConnection sqlConnection = new SqlConnection(conn); //sqlConnection.Open(); msConn().Open(); string query = @"INSERT INTO Mahasiswa VALUES(" + pelajar.Roll + "," + pelajar.English + "," + pelajar.Bahasa + "," + pelajar.Science + ")"; SqlCommand command = new SqlCommand(query, msConn()); command.ExecuteNonQuery(); //sqlConnection.Close(); msConn().Close(); return(true); }
public Pelajar Get(string roll) { pelajar = new Pelajar(); string conn = "Data Source=DESKTOP-V5VOD86\\SQLEXPRESS;Initial Catalog=Universitas;Integrated Security=True"; SqlConnection sqlConnection = new SqlConnection(conn); sqlConnection.Open(); string query = @"SELECT * FROM Mahasiswa WHERE Roll = " + roll.Trim(); SqlCommand command = new SqlCommand(query, sqlConnection); SqlDataReader sqlDataReader = command.ExecuteReader(); while (sqlDataReader.Read()) { pelajar.Id = Convert.ToInt32(sqlDataReader["Id"].ToString()); pelajar.Roll = sqlDataReader["Roll"].ToString(); pelajar.English = Convert.ToDecimal(sqlDataReader["English"].ToString()); pelajar.Bahasa = Convert.ToDecimal(sqlDataReader["Bahasa"].ToString()); pelajar.Science = Convert.ToDecimal(sqlDataReader["Science"].ToString()); } return(pelajar); }