开发者

extracting duplicate records from excel using c#.net

I am new to asp.net.I have an excel sheet which has many duplicate records. I need to display the duplicate records alone saying that these are the duplicates. How can I do it. Is there a particular query to 开发者_开发知识库get only the duplicates.Please help!!


First I will like to suggest you to use "ExcelReaderFactory" to read the excel records.

VB.Net Code

Dim excelReader As IExcelDataReader = Nothing
Dim result As DataSet = Nothing
Dim stream As FileStream = Nothing
stream = File.Open(Server.MapPath("FilePath.xls"), FileMode.Open, FileAccess.Read)
excelReader = ExcelReaderFactory.CreateBinaryReader(stream)
result = excelReader.AsDataSet()
stream.Close()
stream.Dispose()
excelReader.Close()
result.Dispose()

C# Code

IExcelDataReader excelReader = null;
DataSet result = null;
FileStream stream = null;
stream = File.Open(Server.MapPath("FilePath.xls"), FileMode.Open, FileAccess.Read);
excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
result = excelReader.AsDataSet();
stream.Close();
stream.Dispose();
excelReader.Close();
result.Dispose();

After getting the data in datatable you can use select function.

And last Dispose your datatable.


OK, you didn't provide a lot of detail in what you are having trouble with so I'm going to provide you with a good overview of what you need to do. Then you can look at it, work through the examples, and see if you are still confused or missing anything.

Basically, you are going to use the ADO.NET Jet OLEDB connection to Excel to query the data. Basically you will do a SELECT statement. Now I don't believe that you can do a SELECT DISTINCT, which is what would be easiest (please try in order to verify), but you can at least do a SELECT statement to get all of your data into a DataTable.

Once you have your data in the DataTable, you will apply a view, which will allow you to filter out duplicate data. The basic code would be similar to:

ds.Tables["YourTable"].DefaultView.ToTable(true,”uniqueID”);

You can adapt this to your needs. Here are a couple links to help you get started:

How to query Excel from ASP.NET

How to get a distinct row from a DataTable

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜