Ejemplo n.º 1
0
        //***************************************************************************************************************************************************************//
        public static int Insert(Chauffør chauffør)
        {
            SqlConnection cnn     = new SqlConnection(connectionString);
            string        sql     = "Insert into Chauffører(Ch_ID,ForNavn,EfterNavn,Opretdato) values (@Ch_ID,@ForNavn,@EfterNavn,@Opretdato)";
            SqlCommand    command = new SqlCommand(sql, cnn);

            command.Parameters.AddWithValue("@ch_ID", chauffør.Ch_ID);
            command.Parameters.AddWithValue("@ForNavn", chauffør.ForNavn);
            command.Parameters.AddWithValue("@EfterNavn", chauffør.EfterNavn);
            command.Parameters.AddWithValue("@Opretdato", chauffør.OpretDato);

            int result = 0;

            try
            {
                cnn.Open();
                result = command.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                throw new Exception("Fejl: " + e.Message);
            }
            finally
            {
                command.Dispose();
                cnn.Close();
            }
            return(result);
        }
Ejemplo n.º 2
0
        private void but_Gem_Click(object sender, EventArgs e)
        {
            try
            {
                if (IsCustomerNameValid())
                {
                    CurrentChauffør       = new Chauffør();
                    CurrentChauffør.Ch_ID = Int32.Parse(txtCHID.Text);

                    CurrentChauffør.ForNavn   = txtFornavn.Text;
                    CurrentChauffør.EfterNavn = txtEfternavn.Text;
                    CurrentChauffør.OpretDato = dateTime_opret.Value;
                    int result = DataAccessChauffør.Insert(CurrentChauffør);
                    MessageBox.Show("Antal indsatte rækker er: " + result.ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }