CAD.CADComentario.CrearCommentBasic C# (CSharp) Метод

CrearCommentBasic() публичный Метод

Creamos un comentario
public CrearCommentBasic ( string text, int codActividad, string codUser, System.DateTime date ) : void
text string
codActividad int
codUser string
date System.DateTime
Результат void
        public void CrearCommentBasic(string text, int codActividad, string codUser, DateTime date)
        {
            string comando;

            if (codUser == null) {
                comando = "INSERT INTO [Comentario](texto,actividad,fecha) VALUES('" + text + "', '" + codActividad + "', '" + date+ "')";
            } else {
                comando = "INSERT INTO [Comentario](texto,actividad,usuario,fecha) VALUES('" + text + "', '" + codActividad + "', '" + codUser + "', '" + date+ "')";
            }
            SqlConnection c = null;
            SqlCommand comandoTBD;

            try
            {
                c = new SqlConnection(conexionTBD);
                comandoTBD = new SqlCommand(comando, c);
                c.Open();
                comandoTBD.CommandType = CommandType.Text;
                comandoTBD.ExecuteNonQuery();
            }
            catch (SqlException)
            {
                throw;
            }
            finally
            {
                if (c != null) c.Close(); // Se asegura de cerrar la conexión.
            }
        }

Usage Example

Пример #1
0
 //FUNCIONES DE LOS CAD
 public void Agregar()
 {
     CADComentario mens = new CADComentario();
     if (usuario != null)
         mens.CrearCommentBasic(texto, actividadAcademica.Codigo, usuario.DNI, fecha);
     else
         mens.CrearCommentBasic(texto, actividadAcademica.Codigo,null, fecha);
 }