我想使用 Linq to SQL(在 C#/WinForms 项目中)将单个控件属性(TextBox.Text)绑定到数据库字段的组合。
例如:
1)我有一个表 Customer,其中包含 CustomerName、CustomerCity 和 IsBigCustomer 列(布尔值)
2) 在 WinForm 上,我有一个 TextBox "cInfo" 和一个 ListBox "cList"
3) 我已将“cList”绑定到 CustomerName 列(当我更改 cList 中的项目时,我需要 cInfo.Text 中显示的相应客户数据)
4)我想将“cInfo”TextBox.Text 属性绑定到数据库列的组合 - 例如我想显示:
a) "!"+CustomerName+": "+CustomerCity (如果客户的 IsBigCustomer=true)
b) CustomerName+": "+CustomerCity (如果客户的 IsBigClient=false)
当用户更改 cInfo.Text 我需要对其进行验证并将更改发送回数据库(如果验证成功)
Sample data:
{IBM, New York, true} => cInfo.Text should be "!IBM: New York"
(SmallCustomer, Paris, false) => cInfo.Text should be "SmallCustomer: Paris"
我怎样才能完成这项任务?
(问题不在于这种方法的有用性,而是要了解是否可以将多个数据库字段绑定到一个属性以及如何做到这一点)