Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am querying a datatable

C#
var ss = from data in dtRec.AsEnumerable()
                                     where data.Field<string>("Recommendations") == "Contact Vibration Specialist"
                                     select data;


I am getting two values so i want to delete only one value how can i delete?? and i have to update the datatable.
Posted

try it
C#
DataTable dt1 = new DataTable();
dt1 = ds.Tables[0];
for (int i = 0; i < dt.Columns.Count;i++ )
{
if (i == 3)
{
dt.Rows[i - 1].Delete();
dt.AcceptChanges();
}
}
 
Share this answer
 
v2
Comments
chandra sekhar 1-Sep-14 9:38am    
No its not working.
use removeall method to delete record.

Example:
var authorsList = authorsList.Where(x => x.FirstName != "Bob").ToList();

authorsList.RemoveAll(x => x.FirstName == "Bob");
 
Share this answer
 
Comments
chandra sekhar 1-Sep-14 9:22am    
If i get two duplicate values i need to remove only a single value not all.
vangapally Naveen Kumar 1-Sep-14 9:32am    
you are getting same values?
vangapally Naveen Kumar 1-Sep-14 9:35am    
if you are getting same values use group by like
myList.GroupBy(x => x.id)
.Select(g => g.First());
or use distinct

like

myList.DistinctBy(x => x.id);

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