2

我想使用 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"

我怎样才能完成这项任务?

(问题不在于这种方法的有用性,而是要了解是否可以将多个数据库字段绑定到一个属性以及如何做到这一点)

4

1 回答 1

1

如何验证数据。如果您将它放在文本字段中,他们可以输入任何内容,如果有人输入“Some!Big:Company:Bad:!Data”怎么样?这对您有什么作用......

我只能建议在你的表格上,你有类似..

Checkbox for "Big Client"
Textbox for the Name
Textbox for the City

然后,将数据推送回服务器也容易得多。

于 2012-11-02T17:03:42.500 回答