易截截图软件、单文件、免安装、纯绿色、仅160KB

Linq to SQL Like Operator(转载)


As a response for customer's question, I decided to write about using Like Operator in Linq to SQL queries.
Starting from a simple query from Northwind Database;
var query = from c in ctx.Customers
            where c.City == "London"
            select c;
The query that will be sent to the database will be:
SELECT CustomerID, CompanyName, ...
from    dbo.Customers
WHERE  City = [London]
There are some ways to write a Linq query that reaults in using Like Operator in the SQL statement:
1. Using String.StartsWith or String.Endswith
Writing the following query:
var query = from c in ctx.Customers
            where c.City.StartsWith("Lo")
            select c;
will generate this SQL statement:
SELECT CustomerID, CompanyName, ...
from    dbo.Customers
WHERE  City LIKE [Lo%]
which is exactly what we wanted. Same goes with String.EndsWith.
But, what is we want to query the customer with city name like "L_n%"? (starts with a Capital 'L', than some character, than 'n' and than the rest of the name). Using the query
var query = from c in ctx.Customers
            where c.City.StartsWith("L") && c.City.Contains("n")
            select c;
generates the statement:
SELECT CustomerID, CompanyName, ...
from    dbo.Customers
WHERE  City LIKE [L%]
AND      City LIKE [%n%]
which is not exactly what we wanted, and a little more complicated as well.
2. Using SqlMethods.Like method
Digging into System.Data.Linq.SqlClient namespace, I found a little helper class called SqlMethods, which can be very usefull in such scenarios. SqlMethods


相关文档:

SQL 数据库生成自动编号代码

--exec  [P_AutoGenerateNumber]  'reception_apply','generate_code','',7
/*
 过程说明:生成自动编号 
 创建时间:2010年1月12日
 作者:feng
 debug:尚未考虑编号溢出情况
*/ 
ALTER proc [P_AutoGenerateNumber]
  (
  @table ......

sql语句查询

sql语句查询
表结构是这样:
ID   姓名    性别
1    张三     男
2    王四     男
3    丽丽     女
4    张三     男
5    赵柳     男
6    高洁     男
7   ......

C#打包SQL数据库部署安装


参考《ASP.NET与SQL一起打包部署安装》
,这篇文章是针对VB.NET与SQL 一起打包的,但是我使用的是C#,当然只要修改一下主要安装类库就行了!C#的类库代码如下:DBCustomAction.cs
using System;
using System.Collections;
using System.Data.SqlClient;
using System.ComponentModel;
using System.Configuration.Inst ......

ASP.NET2.0分页技术之使用纯sql语句的双top分页篇

Repeater在前台使用比较灵活自由,但有一个问题就是Repeater不支持直接分页,这个很多人看起来就有点不想用了,但我想大家都知道GridView控件或DataGrid控件在启用自带分页的时候其实效率是非常低的,大的不说,一但到了百万级数据以后,就会感觉是多么的痛苦和无耐了,所以即使是用DataGrid(GridView)控件,高手们还是只会 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号