如何通过VB 将datatable中的数据不重复添加进listbox?

如何通过VB 将datatable中的数据不重复添加进listbox?,第1张

必须有唯一标识列才能过滤重复,下面给你个思路:

生成唯一id列:

select id=identity(1,1),bianhao、name、jiage、chandi、shuliang into #tmp_tb from 表1

查询显示name不重复的所有数据:

select * from #tmp_tb t1 where not exists (select 1 from #tmp_tb t2 where t2.name=t1.name and t2.id<t1.id)

bianhao列为唯一标示列,显示大的小的都可以

--------------------

那直接查就可以了:

select * from kucun t1 where not exists (select 1 from kucun t2 where t2.name=t1.name and t2.bianhao<t1.bianhao)

//在addButton的Click事件里将listBox1的项添加到listBox2中,无重复

private void addButton_Click(object sender, EventArgs e)

{

bool flag = false

for (int i = 0i <listBox1.Items.Counti++)

{

foreach (string s in listBox2.Items)

{

if (listBox1.Items[i].ToString() == s)

{

flag = true

}

}

if (!flag)

{

listBox2.Items.Add(listBox1.Items[i])

}

flag = false

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11797242.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存