• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
生活需要积累,积累需要时间,放松心情,慢慢享受
关注.net开发 好好整整Blog,打造好评贴
博客园    首页    新随笔    联系   管理    订阅  订阅

DataSet中利用DataTable,DataView筛选数据

 

thisAdapter.Fill(thisDataSet,"tb");

DataTable thisTable = thisDs.Tables["tb"];
DataView thisView = new DataView(thisTable); //创建DataView对象

thisView.RowFilter = ....;

DataGrid.DataSource = thisView;

...

a,使用sort属性对数据进行排序

thisView.Sort = "ProductName ASC";

or

thisView.Sort = "Age ASC , Name DESC";

b,使用RowFilter属性对数据过滤

thisView.RowFilter =

"ID = 10";

"Num <= 10";

"Date > 1/1/1999 and Date <= 2/2/2005";

"Product in ('apple','cat','table')"

"Text like = '*son'";

注:使用的各条件可用 and 继续添加,在使用 *** in ('','','') 时,注意括号内的项目不易过多,估计能支持十几个.


1,按一对x,y坐标筛选数据 x1 x2 y1 y2

thisView .RowFilter =
"HZBY >= '" + x1 + "' and HZBY <= '" + x2 + "' and ZZBX >= '" + y1 + "' and ZZBX <= '" + y2 + "'";

2,由数组生成筛选条件

//格式为 DataView.Filter = "GZDYMC IN ('job','tree',work')";

string strView = "GZDYMC in (";
int ii = 0;
while(ii < ColTrueNames.Count)
{
strView += "'" + ColTrueNames[ii] + "',";
ii++;
}

strView += "'null')";
thisView.RowFilter = strView;

posted @ 2009-06-17 14:35  黄超  阅读(1065)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3