public void tambahData() { if (tbNama.Text != "" && tbUsia.Text != "" && rbLaki.Checked) { using (var db = new akunModel()) { Akun newAkun = new Akun { Nama = tbNama.Text, Usia = Int32.Parse(tbUsia.Text), JenisKelamin = true, }; db.Tables.Add(newAkun); db.SaveChanges(); } } else if (tbNama.Text != "" && tbUsia.Text != "" && rbPerempuan.Checked) { using (var db = new akunModel()) { Akun newAkun = new Akun { Nama = tbNama.Text, Usia = Int32.Parse(tbUsia.Text), JenisKelamin = false, }; db.Tables.Add(newAkun); db.SaveChanges(); } } }
public Form3() { InitializeComponent(); using (var db = new akunModel()) { var query = from Akun in db.Tables select Akun; foreach (var item in query) { lbNama.Text = item.Nama; lbUsia.Text = item.Usia.ToString() + " tahun"; if (item.JenisKelamin == true) { lbJK.Text = "Laki-laki"; } else if (item.JenisKelamin == false) { lbJK.Text = "Perempuan"; } } } }