在做报表的过程中,需要对表一列中不同的数进行操作。因此需要把这一列不同的数取出放入一个datatable中。
dim test() as string={1,3,1,9,10}
dim dt as datatable=new datatable()
dt.columns.add("fname",System.type.gettype("System.String"))
dim dr as datarow=dt.newrow()
dr("fname")=test(0)
dt.rows.add(dr)
dim N as integer
N=1
dim count as integer=0
for i as integer=1 to 4
dim str as string=test(i)
for j as integer=0 to N-1
dim strc as string=dt.Rows(j)(0)
if(str=strc)then
exit for
else
count=count+1
end if
next
if(count=N)then
dim dr1 as datarow=dt.newrow()
dr1("fname")=str
dt.rows.add(dr1)
N=N+1
end if
count=0
next
这样可以把数组中不重复的数放入表dt中,只是不知道执行时效率如何,等有空再看看有没有其他方法。