我是 c# 的新手,我正在做一个项目,我正在尝试遍历包含不同值的数据表,并且我的数据库的歌曲 ID 为:1,2,3,4,6,8,9,10 但数据集将此值作为分别为 0,1,2,3,4,5,6,7...谢谢
String sql = "select title, song_id from up_song where Song_type='Mp3 Tracks' ";
adpt = new SqlDataAdapter(sql, cn);
ds = new DataSet();
adpt.Fill(ds, "title");
var maxvalue = ds.Tables["title"].AsEnumerable().Max(x => x.Field<int>("song_id"));
var minvalue = ds.Tables["title"].AsEnumerable().Min(x => x.Field<int>("song_id"));
for (i =maxvalue; i >= minvalue; --i)
{
try
{
hyperlink[i] = new HyperLink();
hyperlink[i].ID = "hyperlink" + i;
hyperlink[i].Text = ds.Tables["title"].Rows[i].ItemArray[0].ToString();
hyperlink[i].NavigateUrl = "Downloadpage.aspx";
hyperlink[i].ForeColor = System.Drawing.Color.White;
Panel1.Controls.Add(hyperlink[i]);
Panel1.Controls.Add(new LiteralControl("<br>"));
HttpCookie coo = new HttpCookie("song");
coo["sogtit"] = ds.Tables["title"].Rows[i].ItemArray[0].ToString();
Response.Cookies.Add(coo);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}