This is the code and i need to present the output on screen in a windows form. Would prefer if it is a text box.
var res = (from x in dt.AsEnumerable()
group x by (string)x["Weather"] into y
select new { Key = y.Key, Count = y.Count() }).ToArray();
https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/creating-a-datatable-from-a-query-linq-to-dataset Indicates this should be possible:
var res = from x in dt.AsEnumerable()
group x by (string)x["Weather"] into y
select new { Key = y.Key, Count = y.Count() };
var newdt = res.CopyToDataTable();
datagridview1.DataSouce = newdt;
All that remains is for you to drop a DataGridView control on your form, Ensure it's AutoGenerateColumns property is set to true, and give it a better name than datagridview1 (on the form and in the code above)
You can get the data to List
var r = (from x in test.AsEnumerable()
group x by (string) x["Weather"] into y
select new
{
Key = y.Key, Count = y.Count()
}).ToList();
Then Iterate and get all the data to string and assign that to textbox.Text Property.
string result = "";
foreach ( var weatherData in r )
{
result += weatherData.Key + " " + weatherData.Count + "\r\n";
}
myTextBox.Text = result;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.