I have been spinning my wheels trying to display how many rows there are in my DB into a DataGrid Column called 'JobsCount' using COUNT.
sqlCon.Open();
string query = "SELECT UserName, COUNT(UserName) as count FROM tblJobs WHERE JobStatus != 'Booked' Group by UserName";
SqlCommand cmd = new SqlCommand(query, sqlCon);
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
adapter.Fill(dt);
tblJobsBooked.ItemsSource = dt.DefaultView;
}
sqlCon.Close();
DataGrid Columns
<DataGrid.Columns>
<DataGridTextColumn Header="User" Binding="{Binding UserName}"/>
<DataGridTextColumn Header="Jobs Booked" Binding="{Binding JobsCount}" />
</DataGrid.Columns>
The COUNT should be calculated by UserName.