static void Main(string[] args) { entidades.Profesor objEntidadProfesor = new entidades.Profesor(); //Pedir al usuario que agregue un profesor Console.Write("Ingrese Apellido: "); objEntidadProfesor.Apellido = Console.ReadLine(); Console.Write("Ingrese Nombre: "); objEntidadProfesor.Nombre = Console.ReadLine(); Console.Write("Ingrese Email: "); objEntidadProfesor.Email = Console.ReadLine(); logica.Profesor objLogicaProfesor = new logica.Profesor(); objLogicaProfesor.Agregar(objEntidadProfesor); Console.WriteLine("Profesor Agregado"); Console.ReadKey(); }
//Metodo Agregar public void Agregar(entidades.Profesor profesor) { string strConexion = @"Server=CPX-C5C016FXUF9\TRAINING;database=tecno;Integrated Security=true"; string strSQL = @"insert profesores(apellido,nombre,email) values (@apellido,@nombre,@email)"; SqlConnection objConnection = new SqlConnection(); objConnection.ConnectionString = strConexion; SqlCommand objCommand = new SqlCommand(); objCommand.CommandText = strSQL; objCommand.Connection = objConnection; //Parametros objCommand.Parameters.AddWithValue("@apellido", profesor.Apellido); objCommand.Parameters.AddWithValue("@nombre", profesor.Nombre); objCommand.Parameters.AddWithValue("@email", profesor.Email); //Abro la conexion objConnection.Open(); objCommand.ExecuteNonQuery(); objConnection.Close(); }
public void Agregar(entidades.Profesor pProfesor) { datos.Profesor objProfesor = new datos.Profesor(); objProfesor.Agregar(pProfesor); }