本文介绍了我怎么选择的最小值和最大值的数据值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从数据retrive最小和最大值这些值在面板

 字符串使用for循环显示标题SQL =选择标题,从up_song那里Song_type ='MP3曲目song_id 
SqlDataAdapter的ADPT =新SqlDataAdapter的(SQL,CN);
的DataSet DS =新的DataSet();
adpt.Fill(DS,称号);



所以在这里我想在这里找到分钟和歌曲ID的最大值...
m为最大值和k最小值我不知道......我不知道怎么选择k和m ...?

 对于(i =米; I> = K; --i)
{

{
HP [I] =新的超链接();
HP [I] .ID =惠普+我;
HP [I]。文本= ds.Tables [标题]行[I] .ItemArray [0]的ToString()。
HP [I] .NavigateUrl =Downloadpage.aspx;
HP [I] .ForeColor = System.Drawing.Color.White;
Panel1.Controls.Add(HP [I]);
Panel1.Controls.Add(新LiteralControl(< BR>中));
的HttpCookie COO =新的HttpCookie(宋史);
COO [sogtit] = ds.Tables [标题]行[I] .ItemArray [0]的ToString()。
Response.Cookies.Add(COO);
}
赶上(异常前)
{
的Response.Write(ex.Message);
}
}


解决方案

通过使用的LINQ 扩展方法:

  INT minSongId = ds.Tables [标题] AsEnumerable()
.Min。(R = GT; r.Field< INT>(song_id));
INT maxSongId = ds.Tables [标题] AsEnumerable()
。最大。(R = GT; r.Field< INT>(song_id));


i want to retrive min and max value from dataset and those values use in for loop for display title in panel

    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");

so here i want to find min and max value of song id...here m is max value and k min value i have no idea ...that how i select k and m...?

        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);
            }
        }
解决方案

With using Linq extension methods:

int minSongId = ds.Tables["title"].AsEnumerable()
                  .Min(r => r.Field<int>("song_id"));
int maxSongId = ds.Tables["title"].AsEnumerable()
                  .Max(r => r.Field<int>("song_id"));

这篇关于我怎么选择的最小值和最大值的数据值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 17:12