private void Button1_Click(object sender, RoutedEventArgs e) { frånvarande = false; Child selectedChild = new Child(); attendence attendence = new attendence(); dbOperations db = new dbOperations(); staff staffs = new staff(); staffs.staff_id = 1; DateTime departure = GetTime(); listView1.SelectedItem = selectedChild; db.abscene(staffs.staff_id, (Child)listView1.SelectedItem, GetTime(), frånvarande); MessageBox.Show("Du har anmält frånvaro"); }
public void abscene(int s_id, Child ch_id, DateTime departure, bool attending) { attendence a = new attendence(); a.staff_id = s_id; a.attending = attending; string stmt = "INSERT INTO attendence(staff_id, child_id, departure, attending) VALUES (@s_id, @ch_id, @departure, @attending)"; using (var conn = new NpgsqlConnection(ConfigurationManager.ConnectionStrings["Dbconn"].ConnectionString)) { conn.Open(); using (var cmd = new NpgsqlCommand(stmt, conn)) { cmd.Parameters.AddWithValue("s_id", s_id); cmd.Parameters.AddWithValue("ch_id", ch_id.child_id); cmd.Parameters.AddWithValue("departure", departure); cmd.Parameters.AddWithValue("attending", attending); cmd.ExecuteNonQuery(); } } }