Subscribe to Subscribers
Talk to Webmaster Tony John

Resources » Code Snippets » Active Directory

Find and delete a specific row from datatable


Posted Date:     Category: Active Directory    
Author: Member Level: Gold    Points: 15


If you want to delete specific, multiple or single row delete from data table using by specific condition. Try to below code. You can delete multiple or single row from data table. There is many ways to delete rows from data table. Try Below code.



 


Try to below code. You can delete multiple or single row from data table. There is many ways to delete row(s) from data table.
1.

Delete multiple rows.




string _filterName_needed="approved";
DataRow[] drr = dt.Select("status=' "+ _filterName_needed +" ' ");
for (int i = 0; i < drr.Length; i++)
{
dt.Rows.Remove(drr[i]);
}


.....................................................

Delete only row.



string _filterName_needed="approved";
object obj = dt.Select("status=' "+_filterName_needed+" ' ");
DataRow drr = dt.Rows.Find(obj);
if (drr!=null)
{
drr.Delete();
}


**but you must know that your table must have a primery key to use this method.

Delete row with for loop



for (int i = dt.Rows.Count - 1; i >= 0; i--)
{
if (dt.Rows[i]["status"].ToString() == "approved")
{
dt.Rows[i].Delete();
}
}


I hope it will be useful to developer..





Did you like this resource? Share it with your friends and show your love!


Responses to "Find and delete a specific row from datatable"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: C# - Press Enter Key to move to next control on a Windows Form
    Previous Resource: How to use aggregate function MAX in c#?
    Return to Resources
    Post New Resource
    Category: Active Directory


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Delete row from datatable  .  Remove rows from datatable  .  Delete multiple rows from datatable  .  
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.