© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
5 replies
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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

datagridview not showing data
C#CC# / help
6mo ago
✅ How can i properly display this datagridview
C#CC# / help
4y ago