LinQ 组合查询与分页
1.以开头查
public List<Car> Select1(string a){
return con.Car.Where(r => r.Name.StartsWith(a)).ToList();
}
2.以结尾查
public List<Car> Select2(string a)
{
return con.Car.Where(r => r.Name.EndsWith(a)).ToList();
}
3.最大值
public string Max()
{
return con.Car.Max(r => r.Price).ToString();
}
4.最小值
public string Min()
{
return con.Car.Min(r => r.Price).ToString();
}
5.总和
public string Sum()
{
return con.Car.Sum(r => r.Price).ToString();
}
6.平均值
public string avg()
{
return con.Car.Average(r => r.Price).ToString();
}
7.升序
public List<Car> ss()
{
return con.Car.OrderBy( r =>r.Price).ToList();
}
8.降序
public List<Car> s()
{
return con.Car.OrderByDescending(r => r.Price).ToList();
}
9.组合分页查询
public List<Car> Selecta(int d, string a, string b, string c)
{
List<Car> list = new List<Car>();
list = con.Car.ToList();
if (a != "")
{
List<Car> list1 = con.Car.Where(r => r.Code.Contains(a)).ToList(); list = list.Intersect(list1).ToList();
}
if (b != "")
{
List<Car> list1 = con.Car.Where(r => r.Name.Contains(b)).ToList(); list = list.Intersect(list1).ToList();
}
if (c != "")
{
List<Car> list1 = con.Car.Where(r => r.Brand.Contains(c)).ToList(); list = list.Intersect(list1).ToList();
}
return list.Skip((d--) * PageCount).Take(PageCount).ToList(); } int PageCount = ;
public List<Car> start()
{
return con.Car.Skip( * PageCount).Take(PageCount).ToList();
}
public List<Car> prev(string a)
{
return con.Car.Skip((Convert.ToInt32(a) - - ) * PageCount).Take(PageCount).ToList();
}
public List<Car> next(string a)
{
return con.Car.Skip(Convert.ToInt32(a) * PageCount).Take(PageCount).ToList();
}
public List<Car> end()
{
return con.Car.Skip((max() - ) * PageCount).Take(PageCount).ToList();
} private int max()
{
int count = new CarData().Select().Count; double aa = count / (PageCount * 1.0); return Convert.ToInt32(Math.Ceiling(aa));
}
}
void LinkButton4_Click(object sender, EventArgs e)
{
Repeater1.DataSource = new CarData().end();
Repeater1.DataBind();
Label2.Text = max().ToString();
} private int max()
{
int count = new CarData().Select().Count; double aa = count / (PageCount * 1.0); return Convert.ToInt32(Math.Ceiling(aa));
}
void LinkButton3_Click(object sender, EventArgs e)
{
if (Convert.ToInt32(Label2.Text) < max())
{
int a = Convert.ToInt32(Label2.Text) + ;
Repeater1.DataSource = new CarData().next(Label2.Text);
Repeater1.DataBind();
Label2.Text = a.ToString();
}
else
{
return;
} } void LinkButton2_Click(object sender, EventArgs e)
{ if (Convert.ToInt32(Label2.Text) > )
{
int a = Convert.ToInt32(Label2.Text) - ;
Repeater1.DataSource = new CarData().prev(Label2.Text);
Repeater1.DataBind();
Label2.Text = a.ToString();
}
else
{
return;
}
} void LinkButton1_Click(object sender, EventArgs e)//首页
{
Repeater1.DataSource = new CarData().start();
Repeater1.DataBind();
Label2.Text = "";
} void Button13_Click(object sender, EventArgs e)
{
Label2.Text = "";
int a = Convert.ToInt32(Label2.Text) + ;
Repeater1.DataSource = new CarData().Selecta(a,TextBox3.Text, TextBox4.Text, TextBox5.Text);
Repeater1.DataBind(); int count = new CarData().Select().Count; Label3.Text = Math.Ceiling(Convert.ToDouble(count) / PageCount).ToString(); }
LinQ 组合查询与分页的更多相关文章
- Linq组合查询与分页组合查询结合
1.组合查询 <div>姓名:<asp:TextBox ID="T1" runat="server"></asp:TextBox& ...
- LINQ 组合查询 和分页查询的使用
前端代码 <%@ Page Language="C#" AutoEventWireup="true" Debug="true" Cod ...
- LINQ 小项目【组合查询、分页】
使用 linq 在网页上对用户信息增删改,组合查询,分页显示 using System; using System.Collections.Generic; using System.Linq; us ...
- Web 组合查询加 分页
使用ADO.NET 数据访问技术制作web端组合查询加分页的功能关键在于查询SQL语句的拼接 以Car 表为例 每页显示3条数据 数据访问类使用查询方法,tsql 查询的连接字符串,查询的参数放到Ha ...
- webform组合查询和分页
1.组合查询(1)数据访问类 //参数1:SQL语句 参数2:哈希表public List<Users> chas(string s,Hashtable has) { List<Us ...
- SqlProfilter监控指定数据库数据表——监控linq组合查询生成的sql
1.例子 实际测试环境中往往很多测试都在调用数据库,那么如何使用SqlProfilter监控筛选到自己想要监看的数据库对应的表有关linq生成的sql时候就需要做如下设置了 ........... u ...
- Linq高级查询,分页查询及查询分页结合
一.高级查询与分页查询 1.以...开头 StartsWith Repeater1.DataSource=con.Users.Where(r=>r.Nickname.StartsWith( ...
- linq组合查询时属性扩展问题
学习linq的过程中,做一个表格的条件查询并且分页显示.显示的出的数据需要经过属性拓展来实现将需要给用户看的值显示出来. 后台绑定数据时用的是上下文---- if(!ispostback){ usin ...
- WebForm之Linq组合查询
组合查询 protected void Button1_Click(object sender, EventArgs e) { //默认查询所有,返回的是Table类型,转换成IQueryAble类型 ...
随机推荐
- 【BZOJ4008】[HNOI2015]亚瑟王 期望
[BZOJ4008][HNOI2015]亚瑟王 Description 小 K 不慎被 LL 邪教洗脑了,洗脑程度深到他甚至想要从亚瑟王邪教中脱坑. 他决定,在脱坑之前,最后再来打一盘亚瑟王.既然是最 ...
- win10 install JDK&&JRE
重装系统后,安装的java环境没了,只能重装一下~~~~ 1.下载JDK 2.这里会安装两次,其中第一次为安装 JDK,第二次安装JRE,建议不要将这两个放在同一个文件夹. 3.配置环境变量 用鼠标右 ...
- [IOS] 利用@IBInspectable
某些uiview中设置 这个关键字 IBInspectable 可以让其设置的属性,在右侧的属性栏目里面进行直接设置, 这是最近看了一下wwdc的一个视频学习到的,可以方便的进行 UI的测试,
- Python实战2( 接上):扫描多余中文
还是接上一篇,扫描多余中文,支持自定义忽略字段 源代码,详看 http://pan.baidu.com/s/1ntC78Zv ScanChinese.zip
- Spring MVC:在jsp中引入css
为了将css引入jsp中,今天可真是踩了好多坑,最后在stackoverflow上找到了解决方法,不多说贴出代码. 在web.xml中添加以下代码: <servlet-mapping> & ...
- USACO翻译:USACO 2014 JAN三题(1)
USACO 2014 JAN 一.题目概览 中文题目名称 滑雪场设计 滑雪降速 滑雪场评级 英文题目名称 skidesign slowdown skilevel 可执行文件名 skidesign sl ...
- poj1700-Crossing River(贪心算法)
一,题意: 只有一艘船,能乘2人,船的运行时间为2人中较多一人的时间,过去后还需一个人把船划回来,问把n个人运到对岸,最少需要多久.二,思路步骤: 想办法先把用时最多的2人,运过去,再把剩下来的人中用 ...
- swift 2.x学习笔记(三)
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008400 } p.p2 { margin: 0.0px 0. ...
- uwsgi 安装配置
安装uwsgi# pip install uwsgi 配置uwsgi:首先要明确的是,如果你喜欢用命令行的方式(如shell)敲命令,那可以省去任何配置.但是,绝大多数人,还是不愿意记那么长的命令,反 ...
- 配合 APP 调用 JS 的一次尝试
项目初衷 最初的场景是用户在对购物车的操作中,由于用户对购物车的每次操作(包括选择,调整数量)都需要计算商品的促销和分组的情况,而这段逻辑的计算都需要调用后端的接口,那么瓶颈来了: 请求时间长--一次 ...