DataTable select根据条件取值
1、封装独立方法
// 执行DataTable中的查询返回新的DataTable
/// </summary>
/// <param name="dt">源数据DataTable</param>
/// <param name="condition">查询条件</param>
/// <returns></returns>
private DataTable GetNewDataTable(DataTable dt, string condition,string sortstr)
{
DataTable newdt = new DataTable();
newdt = dt.Clone();
DataRow[] dr = dt.Select(condition,sortstr);
for (int i = ; i < dr.Length; i++)
{
newdt.ImportRow((DataRow)dr[i]);
}
return newdt;//返回的查询结果
}
2、单独写出
DataRow[] drArr = ds.Tables[].Select("ParentID=-1", "MenuOrder asc");
DataTable dtOneLevel = ds.Tables[].Clone();
foreach (DataRow drOneLevel in drArr)
{
dtOneLevel.ImportRow(drOneLevel);
}
3、转泛型筛选
var dtOneLevel = from dt in ds.Tables[].AsEnumerable()
where dt.Field<int>("ParentId") == -
orderby dt.Field<int>("MenuOrder") ascending
select dt;
4、转LInq group by 求count,sum
var temp = from c in dt.AsEnumerable()
group c by c.Field<int>("c3") into g
select new
{
卡位 = g.Key,
数量 = g.Count()
};
--分组求sum
var temp = from c in dt.AsEnumerable()
group c by c.Field<string>("c2") into g
select new
{
部门= g.Key,
数量=g.Sum(c=>c.Field<int>("c3"))
};
DataTable select根据条件取值的更多相关文章
- 浅谈jquery关于select框的取值和赋值
浅谈jquery关于select框的取值和赋值 jQuery("#select_id").change(function(){}); // 1.为Select添加事件,当选择其 ...
- select的种种取值
今天别人问我一个问题 <body> <select id="tests" onchange="test()"> <option & ...
- jquery操作select(选中,取值)
最近工作中总出现select 和 option问题,整理一下,内容大部分源于网络资料 一.基础取值问题 例如<select class="selector"></ ...
- jQuery操作select控件取值和设值
1.级联select的操作,后一个select的值随着前一个select选中值变化 $(".select_A").change(function(){ $(".selec ...
- jquery关于select框的取值和赋值
jQuery("#select_id").change(function(){}); // 1.为Select添加事件,当选择其中一项时触发 var checkValue ...
- jquery操作select(option)的取值,设置和选中
比如 <select class="selector"> <option value ="volvo">Volvo</option ...
- sql-case when 条件1 then 取值1 when 条件2 then 取值2 else 取值3 end
遇到 XXX情况 就 XXX 遇不到就 XXX 结束case when …… then …… else …… end 例如一个3条件取值的字段: case when 条件1 then 取值1 when ...
- easyui 》 radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中
获取一组radio被选中项的值var item = $('input[@name=items][@checked]').val();获取select被选中项的文本var item = $(" ...
- jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中
jQuery获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...}); //为Se ...
随机推荐
- How to step through your code in chrome
By executing code one line or one function at a time, you can observe changes in the data and in the ...
- js点击某个图标或按钮弹出文件选择框
<HTML> <head> <script type="text/javascript" src="script/jquery-1.6.2. ...
- excel出现错误1327 无效的驱动器
错误描述:错误1327 无效的驱动器 错误程序:excel 2003 这是office安装源的位置被移动造 成的的,大部分时候安装时可能使用了移动硬盘或者在安装后调整了盘符就会造成这个问题.官方的 ...
- 【bzoj1076】 SCOI2008—奖励关
http://www.lydsy.com/JudgeOnline/problem.php?id=1076 (题目链接) 题意 一个奖励,K次抛出宝物的机会,每次抛出都等概率的抛出n个物品中的一个,每个 ...
- Android Studio NDK初探
Android Studio中实现NDK开发较之前Eclipse+Cygwin,方便了很多. 本文以最简单的从C程序中获取字符串,并显示到MainActivity的TextView上为例进行NDK开发 ...
- 中软培训第一周复习总结 --简单的HTML 与CSS
一些需要记住的点: day1 HTML格式及简单标签: html 文件一般格式: 1 <html> 2 <head lang="en"> 3 <met ...
- Architectural Model - SNMP Tutorial
30.3 Architectural Model Despite the potential disadvantages, having TCP/IP management software oper ...
- c# 反射类字段
//在wpf中动态绘制Grid布局控件中值 需要来动态获取类中的字段数来自动生成Grid列数或者行数, public class models { public Label name { get; s ...
- ajax 的返回值类型
ajax的dataType类型有三种:text,json,xml. text类型: 主页面: $.ajax({ url:"chuli.php", dataType:&quo ...
- FusionCharts-堆栈图、xml格式、刷新数据、添加事件link、传参
*起因* 本来想用Chart.js来搞图表的, 但是来了个新需求,想搞的华丽点,毕竟对Chart.js来说,实现有点难度, *做出的改变* 最终选择了FusionCharts, *难点* 网上关于Fu ...