如何使用Linq在C#Winforms中使用.Databind方法 [英] How Do I Use .Databind Method In C# Winforms Using Linq
问题描述
Hello House,
我有一个C#winform,我使用linq从数据库中检索记录,如果用户点击一条记录,表格会显示在showdialog上填充记录信息的文本框,决定删除或更新记录,以及创建新记录的链接,我希望能够在gridview上显示新记录或更新的记录,或者已删除角色而未关闭主窗体。有没有我能做到的?
i试过这个:
Hello House,
I have a C# winform, i am using linq to retrieve record from database, if a user clicks on a record, a form is shown on showdialog that populates that record information on a textbox, which the decides either to delete or update the record, and also a link to create new record, i want to be able show on the gridview the new record, or the updated record, or that a role has been deleted without closing the main form. Is there anywhere i can achieve this?
i have tried this:
var dbEntities = new NewSchoolCoreEntities( );
var BindingSource = from a in dbEntities.devices
select new {
IdDevice = a.id,
DeviceType = a.device_type_name,
DeviceName = a.device_name,
ModelNumber = a.model_number ,
MacAddress = a.mac_address,
IsActive = a.device_active,
IsInUse = a.in_use
};
var bindingSource = new BindingSource( );
bindingSource.DataSource = BindingSource.ToList();
dataGridView1.DataSource=bindingSource;
但不工作!任何贡献将不胜感激。谢谢。
but not working! any contribution will be appreciated. Thanks.
推荐答案
这篇关于如何使用Linq在C#Winforms中使用.Databind方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!