im new to c# and i'm trying to fill my datagridview with data from the database and make a groupby on certain column.
for ex:
i have a datagridview that contains : field, fullname and worker_id.
i want to get the data from database and group them according to the field name.
public void FillFullSchedule()
{
using (SqlConnection sqlcon = new SqlConnection(con))
{
sqlcon.Open();
SqlCommand cmd = new SqlCommand("dbo.FullScheduleData", sqlcon);
//SqlDataReader reader = cmd.ExecuteReader();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
fullScheduleDG.Rows.Clear();
foreach (DataRow dr in dt.Rows)
{
int n = fullScheduleDG.Rows.Add();
fullScheduleDG.Rows[n].Cells[0].Value = dr[1].ToString();
fullScheduleDG.Rows[n].Cells[1].Value = dr[0].ToString();
fullScheduleDG.Rows[n].Cells[2].Value = dr[2].ToString();
}
}
}
no problem with that.
i have the code for grouping the data from this post:
https://stackoverflow.com/a/44807088/10534001
but i dont know how to use it. what should i do ?? i dont know the next step.
is it to add events to cellformating or something like that or what ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…