Create a class for your search results with properties of the query results.
public class Applicant
{
public int ID { get; set; }
public string LName { get; set; }
}
while reading, create new instances of Applicant, fill the parameters and insert these instances to the Listbox:
....
Applicant newApplicant;
using (SqlConnection conn)
{
...
using(SqlDatareader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
newApplicant = new Applicant();
newApplicant.ID = reader.GetInt32(0);
newApplicant.LName = reader.GetString(1);
....
ListBox.Items.Add(newApplicant);
}
}
}
By this way, in the listbox you will have instances of Applicant. Under button b, you can get the selected id as:
Applicant selectedApplicant = ListBox1.SelectedItem as Applicant;
int requiredID = selectedApplicant.ID;
As two quick notes, I highly recommend using SqlParameter in sql queries instead of string addition and close any reasources after you are done (like connections, readers, etc)