Datatable 唯一值問題解決

2021-05-18 08:31:07 字數 1828 閱讀 7298

** http://www.cnblogs.com/zeus/archive/2006/10/31/546182.html 謝謝!

我比較喜歡的2種方法:

.net fx 1.0

利用鍵值不能有空指標和重複資料

1object

distinctroomtype 

=getdistinctvalues(dt,

"roomtype");

23here 

isthe method definition. 45

public

object

getdistinctvalues(datatable dtable,

string

colname)

6 14

{} 15} 16

object

objarray 

=new

object

[htable.keys.count ];

17htable.keys.copyto(objarray,0);

18return

objarray;

19}.net fx 2.0一句話:

datatable d 

=datasetname.datatablename.defaultview.totable(

true

, new

string

);

此外補充hashtable的基本用法,轉http://www.cnblogs.com/liuwenjun830/archive/2006/07/28/462182.html

一,雜湊表(hashtable)簡述

在.net framework中,hashtable是system.collections命名空間提供的乙個容器,用於處理和表現類似keyvalue的鍵值 對,其中key通常可用來快速查詢,同時key是區分大小寫;value用於儲存對應於key的值。hashtable中keyvalue鍵值對均為 object型別,所以hashtable可以支援任何型別的keyvalue鍵值對.

二,雜湊表的簡單操作

在雜湊表中新增乙個keyvalue鍵值對:hashtableobject.add(key,value);

在雜湊表中去除某個keyvalue鍵值對:hashtableobject.remove(key);

從雜湊表中移除所有元素:           hashtableobject.clear();

判斷雜湊表是否包含特定鍵key:      hashtableobject.contains(key);

下面控制台程式將包含以上所有操作:

using system;

using system.collections; file使用hashtable時,必須引入這個命名空間

class hashtable}

三,遍歷雜湊表

遍歷雜湊表需要用到dictionaryentry object,**如下:

for(dictionaryentry de in ht) fileht為乙個hashtable例項

四,對雜湊表進行排序

對雜湊表進行排序在這裡的定義是對keyvalue鍵值對中的key按一定規則重新排列,但是實際上這個定義是不能實現的,因為我們無法直接在hashtable進行對key進行重新排列,如果需要hashtable提供某種規則的輸出,可以採用一種變通的做法:

arraylist akeys=new arraylist(ht.keys); file別忘了匯入system.collections

akeys.sort(); file按字母順序進行排序

for(string skey in akeys)

mysql 唯一值 mysql 獲取全域性唯一值

在涉及資料庫儲存資料的時候,經常會遇到唯一值問題,有的是主鍵帶來的限制,有的則是業務上的需要。下面介紹幾種唯一值的獲取或者生產方法 先建乙個測試用的表tbl user,有三個字段 id name age,其中id為主鍵。1 drop table if exists tbl user 2 create...

唯一值獲取

問題 唯一值無法獲取 using system.collections.generic using esri.arcgis.carto using esri.arcgis.geodatabase using system.collections 官網示例 idatastatistics exampl...

loadrunner生成唯一值

void main void getuniquestring int invalue,char outstr id,rand invalue free vuser group 建議把隨機種子 srand unsigned time null 放在指令碼初始化函式裡,只需要初始化一次。若放在子函式裡,...