当前位置: 代码迷 >> ASP.NET >> DataView筛选有关问题
  详细解决方案

DataView筛选有关问题

热度:1117   发布时间:2013-02-26 00:00:00.0
DataView筛选问题
代码如下:
SqlConnection   conn=new   SqlConnection( "server=192.168.1.110;uid=sa;pwd=;database=pubs ");
DataTable   dtb=new   DataTable( "test ");
SqlDataAdapter   adp=new   SqlDataAdapter( "select   *from   employee ",conn);
adp.Fill(dtb);
DataView   view=new   DataView(dtb);
view.Sort= "job_id   asc ";
我现在想取排序好的DataView的前20行该怎么写啊.最后要和Repeater绑定的.

------解决方案--------------------------------------------------------
你的目的就是要对表employee里的job_id字段进行升序排列,然后取前20行记录。。
你可以用在SQL语句中写。 会简单很多噢。。只需把你代码稍作修改
如:
SqlConnection conn=new SqlConnection( "server=192.168.1.110;uid=sa;pwd=;database=pubs ");
DataTable dtb=new DataTable( "test ");
SqlDataAdapter adp=new SqlDataAdapter( "select top 20 * from employee order by asc ",conn);
adp.Fill(dtb);
再直接绑定就可以了```
------解决方案--------------------------------------------------------
直接绑定DataView
------解决方案--------------------------------------------------------
DataView
for(int i=0;i <20;i++)
{

}