Example #1
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            SqlConnection con  = Conexion.agregarConexion();
            SqlCommand    cmm  = new SqlCommand(String.Format("select max(idCientifico) from cientifico"), con);
            SqlCommand    cmm2 = new SqlCommand(String.Format("select idProyecto from proyecto where nomProyecto = '" + comboBox.SelectedItem.ToString() + "'"), con);
            SqlDataReader dr   = cmm2.ExecuteReader();

            dr.Read();
            int idProyecto = int.Parse(dr["idProyecto"].ToString());

            dr.Close();
            Object     o            = cmm.ExecuteScalar();
            int        idCientifico = int.Parse(o.ToString()) + 1;
            Cientifico a            = new Cientifico(idCientifico, textBox.Text, textBox1.Text, idProyecto);
            int        res          = Cientifico.agregarCientifico(a);

            if (res > 0)
            {
                MessageBox.Show("Cientifico dado de alta");
            }
            else
            {
                MessageBox.Show("No se pudo dar de alta");
            }
        }
        public static int agregarCientifico(Cientifico a)
        {
            SqlConnection con;

            con = daiRepaso.Conexion.agregarConexion();
            SqlCommand cmm  = new SqlCommand(String.Format("insert into cientifico (idCientifico, nomCientifico, especialidad) values ('{0}','{1}','{2}')", a.idCientifico, a.nombre, a.especialidad), con);
            SqlCommand cmm2 = new SqlCommand(String.Format("insert into cientificoProyecto (idCientifico, idProyecto) values ('{0}','{1}')", a.idCientifico, a.idProyecto), con);
            int        res  = cmm.ExecuteNonQuery();

            con.Close();
            return(res);
        }