积极答复者
窗体应用的数据绑定问题

问题
答案
-
那怎么对数据进行实时更新啊?比如商品的数量是要实时更新的。
使用Timer每隔一定时间读取数据表的数据,(SqlCommand+DataReader)。
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats- 已建议为答案 Jason Dot WangModerator 2013年3月18日 8:11
- 已标记为答案 Jason Dot WangModerator 2013年3月25日 8:56
-
这个是数据层抛出的异常,你的table adapter写得有bug,结果集和table里面定义的不符,和你数据绑定不绑定没关系。
用table adapter把结果存到data table的话,做不到实时更新,ado.net dataset是为离线数据而设计的。关于如何处理产品数量的同步,去搜索Offline Concurrency Pattern
Visual C++ MVP- 已建议为答案 Jason Dot WangModerator 2013年3月18日 8:14
- 已标记为答案 Jason Dot WangModerator 2013年3月25日 9:02
全部回复
-
标签控件只允许对某个数据源的某个字段进行绑定,而不是绑定这个数据源。
如果你要绑定一批数据,用dataGridView+Timer(实时更新)。
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats -
label1.DataBindings.Add("Text",SomeDataTable,"字段名");
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats -
不能。你只能通过SqlCommand执行一个汇总的SQL语句,然后使用ExecuteScalar方法得到结果,赋值给该Label。
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats -
那怎么对数据进行实时更新啊?比如商品的数量是要实时更新的。
使用Timer每隔一定时间读取数据表的数据,(SqlCommand+DataReader)。
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats- 已建议为答案 Jason Dot WangModerator 2013年3月18日 8:11
- 已标记为答案 Jason Dot WangModerator 2013年3月25日 8:56
-
这个是数据层抛出的异常,你的table adapter写得有bug,结果集和table里面定义的不符,和你数据绑定不绑定没关系。
用table adapter把结果存到data table的话,做不到实时更新,ado.net dataset是为离线数据而设计的。关于如何处理产品数量的同步,去搜索Offline Concurrency Pattern
Visual C++ MVP- 已建议为答案 Jason Dot WangModerator 2013年3月18日 8:14
- 已标记为答案 Jason Dot WangModerator 2013年3月25日 9:02