我將如何結合,如果在數據讀取器?我試過,但在while DR1.Read
它不給我所有的結果雖然和IF在數據讀取器
if(DR1.Read())
{
while(DR1.Read())
{
flowLayoutPanel1.Controls.Add(label);
}
}
else
MessageBox.Show("No results found")
我將如何結合,如果在數據讀取器?我試過,但在while DR1.Read
它不給我所有的結果雖然和IF在數據讀取器
if(DR1.Read())
{
while(DR1.Read())
{
flowLayoutPanel1.Controls.Add(label);
}
}
else
MessageBox.Show("No results found")
試試這個:
if (DR1.HasRows)
{
while (DR1.Read())
{
flowLayoutPanel1.Controls.Add(label);
}
}
else
MessageBox.Show("No results found");
謝謝奧黛麗! :) –
如何使用布爾?
喜歡的東西
bool read = false;
while (DR1.Read())
{
read = true;
}
if (!read)
MessageBox.Show("No results found");
技術上:
if(DR1.Read())
{
do
{
flowLayoutPanel1.Controls.Add(label);
}
while(DR1.Read())
}
else
MessageBox.Show("No results found")
你可以把而在年底,因爲如果目前if(DR1.Read())
已經加載的第一行。
關於此主題,您有一個很好的答案[這裏](http://stackoverflow.com/a/8566729/1257607) – DanielV