Click here to Skip to main content
15,794,593 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);
       {                                                                       Obj_DT_SRDF.Rows.Add(" ", " ", ls_DRName, ls_SRDF_Status, ls_Clone_Status, ls_Time);

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.

1 solution


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

Hope this will help you out in checking the duplicate values and preventing the insertion of the duplicate values.

Sisir patro
Share this answer
Black_Rose 23-Sep-15 2:35am    
Thanks sisir...
[no name] 23-Sep-15 4:39am    
Was that useful?
Black_Rose 28-Sep-15 3:25am    
Yes..That's why i accepted the answer
[no name] 28-Sep-15 6:28am    
Cool... :)
Abu Noumaan 14-Jul-20 5:04am    
Nice Solution! It helped me!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900