There are multiple issues with your code.
First and foremost; your code has an
SQL Injection Vulnerability.
You should
NEVER EVER
create a query by concatenating commands and variables together. the proper thing to do is to use the
SQL Parameter[^] collection to add variables to a command.
That chunk of code should look something like this
SqlCommand cmd = new SqlCommand("SELECT Paid FROM Pay WHERE StdId=@StdId", con);
cmd.Parameters.AddWithValue("@StdId", editstdlbl.Text);
The second part is what you came here for; you are only getting the last value. Well, the problem is you are only reading one value; and what you need to do is go through all the values.
Typically this would be done with a
WHILE
block using the value from the
Reader.Read() as the condition
while (reader.Read()) {
}
But in your case; every time the record is advanced, all you are going to do is to overwrite the value that you set on the prior record.
Unfortunately your question does not have enough detail on what you are trying to actually do with this information, so I cannot tell you what your next steps are going to be to get to where you want to go.
I have ideas on what you may want, some of which have you on the right track and others have you on the wrong track.
References:
MS Docs => SqlParameter Class[
^]
MS Docs => SqlDataReader Class[
^]