如何避免texbox中的数据集重复的值 [英] How to avoid duplicate values from dataset in texbox
本文介绍了如何避免texbox中的数据集重复的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经写了如下的函数
private void PrepUpdate()
{
LicenceBL lbl = new LicenceBL(0);
DataSet lds = new DataSet();
lbl.FetchForEdit(lds, AgentId,BrokerId);
string output ="";
for (int i = 0; i < lds.Tables[0].Rows.Count; i++)
{
output = output + lds.Tables[0].Rows[i]["LicenceTypesNames"].ToString();
output += (i < lds.Tables[0].Rows.Count) ? "," : string.Empty;
}
txtLicenseType.Text = output;
}
它获取所有 LicenceTypesNames
从数据集
,并用,拆分,然后将它们放在文本框中。如果数据集
包含 licencetypesnames
列的重复条目,它们也被插入到文本框中...请帮助我! !
It fetch all the LicenceTypesNames
from dataset
and split them with ',' and then places them in textbox. If dataset
contains duplicate entries for licencetypesnames
column, they are also inserted in the textbox... Please help me!!!
推荐答案
使用 HashSet< string>
在添加
方法
private void PrepUpdate()
{
LicenceBL lbl = new LicenceBL(0);
DataSet lds = new DataSet();
lbl.FetchForEdit(lds, AgentId,BrokerId);
HashSet<string> values = new HashSet<string>();
for (int i = 0; i < lds.Tables[0].Rows.Count; i++)
{
values.Add(lds.Tables[0].Rows[i]["LicenceTypesNames"].ToString());
}
txtLicenseType.Text = string.Join(", ", values.ToList());
}
这篇关于如何避免texbox中的数据集重复的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文