简体   繁体   English

我们是否可以按照排序方式填充文本框中的数据,就像在c#中的数据库中一样

[英]Can we fill the data in the textboxes in a sorted manner as it is in the Database in c#

I am currently using this code to load fields into textboxes: 我目前正在使用此代码将字段加载到文本框中:

this.empTableAdapter.Fill(this.empDataSet.emp);

but the problem if we add a data record with a lesser value of key element than that's already present in database when i click on view all button which invokes this method the last added data is appearing at the the end but i would like to have it appear in a sorted manner. 但问题是,如果我们添加一个数据记录的关键元素值比数据库中已经存在的数据记录更少,当我点击查看调用此方法的所有按钮时,最后添加的数据出现在最后,但我想拥有它以排序的方式出现。

i Have setup two navigation buttons to navigate to next and previous field. 我已设置两个导航按钮以导航到下一个和上一个字段。

The data is being sorted in my database but when i invoke it by the 数据正在我的数据库中进行排序,但是当我通过它调用它时

this.empTableAdapter.Fill(this.empDataSet.emp);

its not getting updated like that. 它不会像那样更新。

How can I achieve this? 我怎样才能做到这一点?

The simple solution to this problem would be not to bind directly to the empTableAdapter, but instead use an intermediary BindingSource . 解决这个问题的简单方法是不直接绑定到empTableAdapter,而是使用中间BindingSource

The way this works is that you assign the TableAdapter as the source for the BindingSource, and then use the BindingSource when data binding to your UI components. 这种方式的工作方式是将TableAdapter指定为BindingSource的源,然后在数据绑定到UI组件时使用BindingSource。

The BindingSource has options to ensure that your data remains filtered and sorted, and is further supported by nice UI controls for paging/navigation. BindingSource具有确保您的数据保持过滤和排序的选项,并且由用于分页/导航的良好UI控件进一步支持。

I haven't used DataSets for a long time now, but as I recall this call all be created and wired up using the component toolbox and windows forms designer. 我现在已经很久没有使用DataSet了,但是我记得这个调用都是使用组件工具箱和windows窗体设计器创建和连接的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM