public string AddDataMapel(Mapel dp) { SqlCommand cmd = new SqlCommand("insert into mapel(ID_Mapel,Nama_Mapel,Nama_Jurusan) values(" + "'" + dp.id_mapel + "'," + "'" + dp.nama_mapel + "'," + "'" + dp.nama_jurusan + "')", conn); try { conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); return("Data Berhasil Di Simpan"); } catch (Exception ex) { return("Data Gagal Di Simpan : " + ex); } }
public List <Mapel> GetMapel() { //string query = String.Format("Update pesanan set pesanan") List <Mapel> dp = new List <Mapel>(); SqlCommand cmd = new SqlCommand("select * from mapel", conn); conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Mapel pesan = new Mapel(); pesan.id_mapel = reader["ID_Mapel"].ToString(); pesan.nama_mapel = reader["Nama_Mapel"].ToString(); pesan.nama_jurusan = reader["Nama_Jurusan"].ToString(); dp.Add(pesan); } conn.Close(); return(dp); }