Exemplo n.º 1
0
 public void DtgConnect(object Grilla)
 {
     using (tareasEntities db = new tareasEntities())
     {
         ((DataGridView)Grilla).DataSource = db.tareas.ToList();
     }
 }
Exemplo n.º 2
0
        //Metodo para Grabar una nueva Tarea
        public string NTarea(object[] Textos, object Date)
        {
            string rpta = "";

            try
            {
                using (tareasEntities db = new tareasEntities())
                {
                    tareas tarea = new tareas();
                    tarea.titulo      = ((TextBox)Textos[0]).Text;
                    tarea.descripcion = ((TextBox)Textos[1]).Text;
                    tarea.fecha       = ((DateTimePicker)Date).Value;
                    tarea.telefono    = Convert.ToInt32(((TextBox)Textos[2]).Text);
                    tarea.estado      = "CREADO";
                    db.tareas.Add(tarea);
                    db.SaveChanges();

                    rpta = "OK";
                }
                return(rpta);
            }
            //cath para saber sobre error en Entity Framework
            catch (DbEntityValidationException ex)
            {
                StringBuilder sb = new StringBuilder();

                foreach (var failure in ex.EntityValidationErrors)
                {
                    sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType());
                    foreach (var error in failure.ValidationErrors)
                    {
                        sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage);
                        sb.AppendLine();
                    }
                }

                throw new DbEntityValidationException(
                          "Entity Validation Failed - errors follow:\n" +
                          sb.ToString(), ex

                          ); // Add the original exception as the innerException
            }

            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                rpta = e.Message;
                return(rpta);
            }
        }