How to remove Duplicate Rows from DataTable in Asp.Net


Description:- In This Example We Will See How to Remove Duplicate Value or Rows from DataTable or Database or Data View So I Gave One Example to Understand How we can remove or Delete Duplicate Value from DataTable.

Step 1: Create Webpage in your Project.
Step 2: Drag and Drop GridView Controls in your Webpage to See Data in Browser easily.
Step 3: Now Design your GridView Controls Like below Image.


Step 4: Now Go to Code behind File and Add Data in GridView Controls for that I have Created Data Table to Save Data in GridView and Add Range in DataTable. After Your DataTable Object Store in ViewState to Maintain Data and Bind GridView Control Call This All in Page_Load event.


Step 5: Now double Click on Button to Generate Click Event and Code for Remove Duplicate Value from DataTable. Here I Have used DataTable so there is Solution to Remove Duplicate Value from DataTable.

DataTable dt = (DataTable)ViewState["dt"];
dt = dt.DefaultView.ToTable(true, "Id", "Name", "Country");

So This Will Remove Duplicate value and Give Distinct Value.
Step 5: Now Run your Webpage in Browser to See How to Remove Duplicate Value.


Step 6: Now Click Remove Duplicate Button to Remove Duplicate Value from Data Table and See Only Distinct Value.

Related Posts

Previous
Next Post »

Thanks for comments.....