ok, i see some problems with your code, but i do not fully understand your question so i'll answer it as much as i can.
first of all, as i wrote, remove the if (dr.Read())
, because the while
loop already do that.
now, there is a problem on the inside of your loop because it meant that if you have several items they will override the previous, and you'll be left with the last item values, so you have to figure what you want to do with the data, maybe a dataGrid
or something.
in your question you are talking about your query, that if you don't put value in MyGlobals.Patient_code
the query still works, at least i think that's what you meant. might be because then you're left with the last value or a string.empty
value that you might have in your database. check the database and the value you have each time when you get to that line and tell us more about your question if you want further help