用于删除重复记录的循环 [英] For loop which delete the duplicate Records

查看:93
本文介绍了用于删除重复记录的循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI Everyone,



很高兴看到你们所有人。



我正在努力建立我的逻辑。我已经完成了部分的一半但我陷入了这种情况。

我正在寻找一个For循环,删除重复的Records.Duplicate记录,意义如下:

我的Excel表格名称如下:雇员

Sr.No姓名姓氏

1 Amit podar

2 Salman khan

3 Amit podar



在这个场景中,我想阅读所有记录,但在阅读完所有记录之后我只想插入前两个记录,因为第三个记录是重复,我不想在数据库中插入。我想使用for循环相同。

亲切的建议。

谢谢Harshal

HI Everyone,

Nice to See u all.

I am trying to build my logic .I ahve completed the half of the part but i got stuck into this situation.
I am searching for a For loop which delete the duplicate Records.Duplicate records in the sense For Examle:
I have a columns as follows for Excel Sheet name: Employee
Sr.No Name Surname
1 Amit podar
2 Salman khan
3 Amit podar

In this Scenario,I want to read all the records but after reading all records i want to insert only first two records because third records is duplicate that i dont want to insert in database.I want to use for loop for the same.
Kindly advice.
Thanks Harshal

推荐答案

使用字典对象。阅读时,您可以查看ContainsKey功能,看看它是否已经添加。



参见这里 [ ^ ]



希望这会有所帮助。
Use a dictionary object. When reading you can check the "ContainsKey" function to see if it was already added or not.

See here[^]

hope this helps.


通过List Contain方法删除重复值

Remove duplicate values through List Contain method
public string[] RemoveDuplicates(string[] inputArray)
{
    List<string> distinctArray = new List<string>();
    foreach (string element in inputArray)
    {
        if (!distinctArray.Contains(element))
            distinctArray.Add(element);
    }

    return distinctArray.ToArray<string>();
}



通过ArrayList删除重复元素包含方法


Delete Duplicate elements through ArrayList Contain method

public string[] RemoveDuplicates(string[] inputArray)
{
    System.Collections.ArrayList distinctArray = new System.Collections.ArrayList();

    foreach (string element in inputArray)
    {
        if (!distinctArray.Contains(element))
            distinctArray.Add(element);
    }

    return (string[])distinctArray.ToArray(typeof(string));

}


在插入之前,您可以遍历记录并检查数据库中的现有记录。
You can loop through the records and check for the existing in the database before inserting.


这篇关于用于删除重复记录的循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆