用于删除重复记录的循环
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.