如何从 linq 查询和实体模型绑定的 datagridview 更新数据库?
我从 linq 查询绑定 datagridview,但我不知道当用户对 datagridview 进行更改时如何将其更新到数据库。
var q = from w in dowacodbEntities.worksheets
where w.ContractForm_id.Equals(g_ContractID)
orderby w.id
select new
{
w.id,
w.UnitPrice,
w.LabourCost
};
BindingSource bindingSource = new BindingSource(); // use bindingsource
bindingSource.DataSource = q.ToList(); // convert linq query to bindingsource
dataGridView1.DataSource = bindingSource; // add bindingsource to datagridview
p/s:我正在使用 C# winform
I bind a datagridview from a linq query, but I don't know how to make it updated to database when users makes changes on the datagridview.
var q = from w in dowacodbEntities.worksheets
where w.ContractForm_id.Equals(g_ContractID)
orderby w.id
select new
{
w.id,
w.UnitPrice,
w.LabourCost
};
BindingSource bindingSource = new BindingSource(); // use bindingsource
bindingSource.DataSource = q.ToList(); // convert linq query to bindingsource
dataGridView1.DataSource = bindingSource; // add bindingsource to datagridview
p/s : I'm using C# winform
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这是同样的问题
WinForms DataGridView - 更新数据库
I think this is the same problem
WinForms DataGridView - update database