Update Row In Datatable Using Linq Distinct Select
If you need your results as a DataTable, you could do: DataTable results = myDataTable.AsEnumerable().Distinct().CopyToDataTable(); Lastly, if your distinct logic needs to be more complicated than the default implementation, you can easily use your own equality comparer.
So, if I'm understanding you correctly, you want to find all rows from a table where certain fields contain certain information and just select the entire row? If so, I think you are getting too complicated. You need to identify the object to test, in this case a datarow, followed by the collection, in this case all the rows of the datatable, perform your criteria on the row just as if you were doing a foreach statement and had access to the variable you defined after the from, and then select the variable you defined. Like so DataTable dt = new DataTable(); DataRow row; dt.Columns.Add(new DataColumn('id',typeof(int))); row = dt.NewRow(); row['id'] = 1; dt.Rows.Add(row); row = dt.NewRow(); row['id'] = 2; dt.Rows.Add(row); row = dt.NewRow(); row['id'] = 3; dt.Rows.Add(row); MessageBox.Show((from DataRow r in dt.Rows where r['id'].ToString() == '1' select r).Count().ToString()); Select all. Hi robkolsky I must be missing something I am very new to C#, I am not sure why you are providing and id to the Columns, when they already have field headers in the datatable. I have already built all of this code in normal switch statement but it is very long winded as well as providing difficulty in separating the row data; and LINQ promises to simplify by query directly to object.
I have a datatable with a field called 'Status' and in that field I will get 3 variables 'PENDING', 'SUCCESS' or 'FAIL'. I am attempting to use LINQ to get all the row data where status = PENDING.
Hello, I used the above query. Two issues I am facing: 1. There are 3 rows in the data table. But only 2 rows get added to the hash table. Any reason why? Please note that I want distinct only for state name and not for country.
When i try to retrieve country name from the hash table for given state, I get error. Following is the code for this: if hash.Containskey(cboState. Text) = True then 'Below line gives error txtCountry.Text =hash.Item(country).ToStri ng End if Basically what I need is that when the user selects any state from the combo box, I want to search this state in the hash table and get the country desc. First part of the problem is resolved. Contoh jadwal supervisi manajerial kepala sekolah mtsu.
But I am still not able to access the entries from the hash table. As suggested, I wrote: txtCountry.Text = hash(country) But it gives error - country not defined. I think it is treating country as variable. So I put country within quotes as txtCountry.Text = hash('country'). It still returns Nothing whereas the statement ----- if hash.Containskey(cboState. Text) = True then ---- is correct since cboState value is there in the has table. So it means we need to rewrite the line - txtCountry.Text = hash(country) Regards, mi.