This time we will discuss how to create a group by on a datatable to calculate COUNT using LINQ.
The example that I will use is employee attendance data. The table on the left is the raw data of employee attendance data that contains employee name and date in columns. Then the data will be displayed in a summary of the number of days of attendance as in the table on the right.
I've already had a window project with C# . The UI is designed as below:
We'll use LINQ, DataTable, and create a function to convert LINQ result into datatable, so wee need to use/import these classes:
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.AllowUserToAddRows = false;
button1.Text = "Show Data";
}
Function to convert LINQ result into DataTable named LINQResultToDataTable.
public static DataTable LINQResultToDataTable<T>
(IEnumerable<T> Linqlist)
{
DataTable dt = new DataTable();
PropertyInfo[] columns = null;
Let's try to run debug.
0 Comments