So far, and IF in the data reader

How will I combine time and if in a data reader? I tried this, but in while DR1.Read it does not give me the whole result

 if(DR1.Read()) { while(DR1.Read()) { flowLayoutPanel1.Controls.Add(label); } } else MessageBox.Show("No results found") 
+4
source share
3 answers

Try the following:

  if (DR1.HasRows) { while (DR1.Read()) { flowLayoutPanel1.Controls.Add(label); } } else MessageBox.Show("No results found"); 
+3
source

How about using bool?

Sort of

 bool read = false; while (DR1.Read()) { read = true; } if (!read) MessageBox.Show("No results found"); 
+1
source

Technically:

 if(DR1.Read()) { do { flowLayoutPanel1.Controls.Add(label); } while(DR1.Read()) } else MessageBox.Show("No results found") 

you can put this at the end because if(DR1.Read()) already loads the first line if present.

0
source

Source: https://habr.com/ru/post/1497553/


All Articles