c# – 访问DataReader中的特定行
作者:互联网
我有一个datareader来显示js轮播中的游戏周列表.
我需要能够添加一个if语句来更改当前游戏周的div类.
这是我目前的代码:
if (dReader.HasRows) {
while (dReader.Read()) {
gameweekList.Text += "<div class=\"item\"><h4>Gameweek " +
(dReader["gameweekID"].ToString()) + "</h4></div>";
}
} else {
gameweekList.Text = "Error Finding Gameweeks";
}
dReader.Close();
conn.Close();
实际上我想添加if(dreader [1])然后添加额外的位,这怎么可能?
解决方法:
怎么样…
if (dReader.HasRows) {
while (dReader.Read()) {
if ( dReader["gameweekID"].ToString() == currentWeekId )
{
gameweekList.Text += "<div class=\"somethingSpecial\"><h4>Gameweek " +
(dReader["gameweekID"].ToString()) + "</h4></div>";
}
else
{
gameweekList.Text += "<div class=\"item\"><h4>Gameweek " +
(dReader["gameweekID"].ToString()) + "</h4></div>";
}
}
} else {
gameweekList.Text = "Error Finding Gameweeks";
}
dReader.Close();
conn.Close();
标签:c,asp-net,datareader,sqldatareader 来源: https://codeday.me/bug/20190715/1468627.html