データベーステーブルから最新の6行を取得しようとしていますが、最大値を使用していますが、テーブルから制限された6行を取得し、その取得結果をforループで使用してパネルにハイパーリンクを表示する方法
protected void Page_Load(object sender, EventArgs e)
{
String sql = "select title from up_song ";
SqlDataAdapter adpt = new SqlDataAdapter(sql, cn);
DataSet ds = new DataSet();
adpt.Fill(ds, "title");
if (ds.Tables["title"].Rows.Count > 0)
{
int m = ds.Tables["title"].Rows.IndexOf(ds.Tables["title"].Rows[8]);
int k = ds.Tables["title"].Rows.IndexOf(ds.Tables["title"].Rows[1]);
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);
}
}
}
String sql1 = "select title from up_song where Song_type='Indian Pop Album'";
SqlDataAdapter adpt1 = new SqlDataAdapter(sql1, cn);
DataSet ds1 = new DataSet();
adpt1.Fill(ds1, "title");
if (ds1.Tables["title"].Rows.Count > 0)
{
String query = "select max(song_id) from up_song;";
SqlDataAdapter adpt2= new SqlDataAdapter(query,cn);
DataSet ds2= new DataSet();
adpt2.Fill(ds2,"max");
//int m = ds.Tables["title"].Rows.IndexOf(ds1.Tables["title"].Rows[query]);
//int k = ds.Tables["title"].Rows.IndexOf(ds.Tables["title"].Rows[1]);
for (i = 0; i <= ds2.Tables["max"].Rows.Count; ++i)
{
try
{
hp[i] = new HyperLink();
hp[i].ID = "hp" + i;
hp[i].Text = ds1.Tables["title"].Rows[i].ItemArray[0].ToString();
hp[i].NavigateUrl = "Downloadpage.aspx";
hp[i].ForeColor = System.Drawing.Color.White;
Panel2.Controls.Add(hp[i]);
Panel2.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);
}
}
}
cn.Close();