[英]How to bind data from mutiple tables to datagridview using Entity Framework and use CRUD operations?
Can some one please give a example of how to bind result to a datagridview which taken from multiple tables (from a join query) in entity framework. 有人可以举例说明如何将结果绑定到实体框架中从多个表(来自连接查询)获取的datagridview。 actually i can bind data to the datagridview but when i call
实际上,我可以将数据绑定到datagridview但是当我调用时
context.SaveChanges(); context.SaveChanges(); nothing has updated in the database.
数据库中没有更新任何内容。 How to correctly bind data to datagridview with Update,Insert,Delete functions.
如何使用Update,Insert,Delete函数将数据正确绑定到datagridview。
This is what i tried. 这是我试过的。
public class DataBindingProjection
{
public string dono { get; set; }
public int apmntid { get; set; }
public string servicedesc { get; set; }
public string cusid { get; set; }
public string empid { get; set;
public bool isdelivered { get; set; }
}
context = new HHCSEntities();
var query = from d in context.DeliveryOrders
join a in context.Appointments on d.ApmntId equals a.ApmntId
join s in context.ServiceCategories on d.ServiceId equals s.ServiceId
join e in context.Employees on d.EmpId equals e.EmpId
select new DataBindingProjection
{
dono = d.DONo,
apmntid = a.ApmntId,
servicedesc = s.ServiceDesc,
cusid = a.CusId,
empid = d.EmpId,
shortname = e.ShrtName,
isdelivered = d.IsDelivered
};
dataGridView1.DataSource = query.ToList();
dataGridView1.Columns[1].DataPropertyName = "dono";
dataGridView1.Columns[2].DataPropertyName = "apmntid";
dataGridView1.Columns[3].DataPropertyName = "servicedesc";
dataGridView1.Columns[4].DataPropertyName = "apmntid";
dataGridView1.Columns[5].DataPropertyName = "empid";
dataGridView1.Columns[9].DataPropertyName = "isdelivered";
Thanks in advance. 提前致谢。
After to give result of your query, you should write this: 在给出查询结果之后,你应该这样写:
...
BindingSource bi = new BindingSource();
bi.DataSource = query.ToList();
dataGridView1.DataSource = bi;
dataGridView1.Refresh();
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.