How to search by means of ID and modify or delete ASP.NET

0

I commented that this is my update code, this code I leave my controller I did, the question is how can I make my method to search by id and then do the action of delete or update, they would be so kind to support me, please, I leave my method of liminar ..

 public  void Actualizar(Alumno objAlumno)
        {
            string actualizar = "update Persona set nombre='" + objAlumno.IdAlumno + "',Apellido='" + objAlumno.Apellido1 + "',Telefono='" + objAlumno.Telefono1 + "' Where idAlumno ='" + objAlumno.IdAlumno + "'";
            try
            {
                conn = new SqlCommand(actualizar, objConexion.getcon());
                objConexion.getcon().Open();
                conn.ExecuteNonQuery();
            }

            finally
            {
                objConexion.getcon().Close();
                objConexion.cerrarConexion();
            }
        }
     public ActionResult Editar()
                {
                    return View();
                }
                [HttpPost]
                public ActionResult Editar(Alumno objAlumno)
                {



                AlumnoDao ins = new AlumnoDao();
    ins.find(objAlumno);
    //AlumnoDao ins = new AlumnoDao();
    //ins.Actualizar(objAlumno);
    return View("Editar" );

                }
______________________________________________________________________________

   public void Eliminar(Alumno objAlumno)
        {
            string eliminar = "'delete from Persona where idAlumno ='" + objAlumno.IdAlumno + "'";

            try
            {
                conn = new SqlCommand(eliminar, objConexion.getcon());
                objConexion.getcon().Open();
                conn.ExecuteNonQuery();
            }

            finally
            {
                objConexion.getcon().Close();
                objConexion.cerrarConexion();
            }
        }

This is my search method

public bool find(Alumno objAlumno)
        {
            bool ExistenRegistros;
            string find = "select * from Persona where idAlumno = '" + objAlumno.IdAlumno + "'";
            try
            {
                conn = new SqlCommand(find, objConexion.getcon());
                objConexion.getcon().Open();
                SqlDataReader read = conn.ExecuteReader();
                ExistenRegistros = read.Read();
                if (ExistenRegistros)
                {
                    objAlumno.IdAlumno = Convert.ToInt32(read[0].ToString());
                    objAlumno.Nombre = read[1].ToString();
                    objAlumno.Apellido1 = read[2].ToString();
                    objAlumno.Telefono1 = read[3].ToString();

                    objAlumno.Estado = 99;

                }
                else
                {
                    objAlumno.Estado = 1;
                }
            }
            finally
            {
                objConexion.getcon().Close();
                objConexion.cerrarConexion();
            }
            return ExistenRegistros;

        }
    
asked by Chuy Mogollan 11.12.2018 в 20:50
source

0 answers