C#C
C#3y ago
Williamo

❔ ✅ Trying to sort and display data in datagridview

Currently i can sort the data but it only displays the last row of data because of the for loop but im unsure of how to make it display all the rows with the certain value that it is searching for


private void Loaddata()
{
for (int x = 0; x < Classes.Access.StaffDetails.StaffIDList.Count; x++)
{
findstaffID = Classes.Access.StaffDetails.StaffIDList[x].StaffID;


using (SqlConnection connection = new SqlConnection(Classes.SystemClass.DBConnection.cs))
{


string sqlQuery = string.Format("SELECT * FROM Staff WHERE StaffID = '{0}'",
findstaffID);
SqlCommand Select = new SqlCommand(sqlQuery, connection);
SqlDataAdapter adapter = new SqlDataAdapter(Select);
DataSet set = new DataSet();
adapter.Fill(set);
StaffDataGridView.DataSource = set.Tables[0];
}
}
}
image.png
Was this page helpful?