避免数据表中的重复条目 [英] Avoid duplicate entries in data table
本文介绍了避免数据表中的重复条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我在数据表中绑定数据,我在同一行中输入3次。
下面是代码
Hi all
I am binding data in a data table where i am getting entries 3 times for same row.
below is the code
if (ls_SRDF_Status != "")
{
ls_DRName = ls_DRName.Replace("_clone_file", "");
if (intchck_1 == 1)
{ Obj_DT_SRDF.Rows.Add(ls_IP, ls_SerialNumber, ls_DRName, ls_SRDF_Status, ls_Clone_Status, ls_Time);
}
else
{ Obj_DT_SRDF.Rows.Add(" ", " ", ls_DRName, ls_SRDF_Status, ls_Clone_Status, ls_Time);
}
}
这里我想检查一下,如果ls_DRName是已经在数据表中然后不添加那一行。
请告诉我怎么做。
Here i want to check wach time that if "ls_DRName" is already there in data table then don't add that row.
Please tell me how to do this.
推荐答案
您好,
您可以使用数据表进行搜索操作,并了解是否有特定值的条目。检查是否可以遵循以下代码:
Hi,
you can do a search operation with the datatable and get to know whether there is an entry for the particular value or not. For checking that you can follow following code:
DataRow[] found = Obj_DT_SRDF.Select("ls_DRName = '" + ls_DRName + "'");
if(found.Length == 0)
{
// Insert the record or else don't insert
}
希望这可以帮助您检查重复值并防止插入重复值。
谢谢,>
Sisir patro
Hope this will help you out in checking the duplicate values and preventing the insertion of the duplicate values.
Thanks,
Sisir patro
这篇关于避免数据表中的重复条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文