using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
using(EntityDataModelBitacora db= new EntityDataModelBitacora())
{
var listaUsuario2 = from datosUsuario in db.Usuario
select new { datosUsuario.estado,datosUsuario.nombre };
dgvUsuario.DataSource = listaUsuario2.ToList();
}
}
}
}
=========================================================================
APLICACION MEJORADA
==================================================================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Refrescar()
{
using (EntityDataModelBitacora db = new EntityDataModelBitacora())
{
var listaUsuario2 = from datosUsuario in db.Usuario
select datosUsuario;
dgvUsuario.DataSource = listaUsuario2.ToList();
}
}
private void Insertar_Click(object sender, EventArgs e)
{
using(EntityDataModelBitacora db=new EntityDataModelBitacora())
{
Usuario oUsuario= new Usuario();
oUsuario.idUsuario = textBox1.Text;
db.Usuario.Add(oUsuario);
db.SaveChanges();
Refrescar();
}
}
}
}
No hay comentarios.:
Publicar un comentario