C
C#8mo 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]; } } }
No description
4 Replies
Williamo
Williamo8mo ago
only displays one row !close
Accord
Accord8mo ago
Closed!
Jimmacle
Jimmacle8mo ago
i know you closed this but you should use parameterized SQL queries instead of string formatting, you're creating a SQL injection vulnerability in your code
Accord
Accord8mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.