您的位置:首页 > 移动开发

DataSet中利用DataTable,DataView筛选数据.

2005-11-07 18:29 489 查看
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 ('','','') 时,注意括号内的项目不易过多,估计能支持十几个.
eg;
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;
想要了解某人的话,首先要知道对方反感什么.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐