一个已经创建的DataTable对象使用SELECT DISTINCT? [英] Using SELECT DISTINCT on an already created DataTable object?

查看:948
本文介绍了一个已经创建的DataTable对象使用SELECT DISTINCT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我使用我的girdview(asp.net)我还需要该对象的列绑定到一个DropDownList一个已经创建的DataTable对象。该表具有列正确的细节,但该列中包含更多的列同名的1 - 因此我很想只是做一些对数据表的SELECT DISTINCT,并把它复制到一个新的DataTable为使用绑定下拉。

I have an already created DataTable object which i am using for my girdview (asp.net) i also need to bind a column of that object to a DropDownList. The datatable has the correct details in the column but the column contains more that 1 of the same name in the column - hence I would love to just do some kind of SELECT DISTINCT on the datatable and copy it to a new datatable for use with binding the dropdown.

这将使我通过再次访问数据库,以节省资源。

This would allow me to save resources by making another trip to the database.

下面是一个例子,当前的表具有一个柱被称为项目,并在此列具有以下输入

Here is an example, the current datatable has a column called items and in this column has the following entries

1
1
1
1
5
5
6

当然,我只需要独特的项目绑定到我的下拉列表中,因此,我需要准备以下数据

And of course i need only unique items for binding to my dropdown, hence i need the following data

1
5
6

当然,我不想改变原来的DataTable对象,而是做它的一个副本将新的细节

Of course i don't want to change the original datatable object but rather make a copy of it will the new details

任何想法,如果这是可能的吗?或者我需要做另一行的分贝?

Any ideas if this is possible ? Or do i need to make another trip to the db?

在此先感谢

推荐答案

DataTable的DT =新的DataTable();
DT = dsMobileInfo.Tables [0] .DefaultView.ToTable(真的ColumnName);

DataTable dt = new DataTable(); dt = dsMobileInfo.Tables[0].DefaultView.ToTable(true, "ColumnName");

//运用dvResult数据设置为网格
的for(int i = 0;我

希望这会为你工作。

//Applying the dvResult data set to the Grid for(int i=0;i

Hope This will work for you.

这篇关于一个已经创建的DataTable对象使用SELECT DISTINCT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆