-1
    String sql = "select  title, song_id from up_song where Song_type='Mp3 Tracks' ";
    SqlDataAdapter adpt = new SqlDataAdapter(sql, cn);
    DataSet ds = new DataSet();
    adpt.Fill(ds, "title");
    var m = ds.Tables["title"].AsEnumerable().Max(x => x.Field<int>("song_id"));
    var k = ds.Tables["title"].AsEnumerable().Min(x => x.Field<int>("song_id"));
 for (i = m; i >= k; --i)
        {
            try
            {
                hp[i] = new HyperLink();
                hp[i].ID = "hp" + i;
                hp[i].Text = ds.Tables["title"].Rows[i].ItemArray[0].ToString();
                hp[i].NavigateUrl = "Downloadpage.aspx";
                hp[i].ForeColor = System.Drawing.Color.White;
                Panel1.Controls.Add(hp[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);
            }
        }
    }

在这里我遇到了一个错误,错误是:

位置 9 没有行。位置 8 没有行。位置 7 没有行。

那么代码有什么问题???

我无法从数据库访问值 另一种解决方案是什么谢谢?

4

1 回答 1

0

如果您的数据库中有 SongId 3,4,5,6,7,8,9 那么

m is 9

k is 3

但是您的 DataTable 只有七行 (0-6)。然后你不能使用 id 作为行索引来访问它们。

于 2013-02-11T13:19:16.373 回答