三层架构的使用(Use of three-tier architecture)

sql语句的各种模糊查询

一般模糊语句如下:SELECT 字段 FROM 表 WHERE 某字段 Like 条件

其中关于条件,SQL提供了四种匹配模式:

a.%:表示任意0个或多个字符。可匹配任意类型和长度的字符,有些情况下若是中文,请使用两个百分号(%%)表示。

SELECT * FROM [user] WHERE u_name LIKE ‘%三%’——将会把u_name为“张三”,“张猫三”、“三脚猫”,“唐三藏”等等有“三”的记录全找出来

b._: 表示任意单个字符。匹配单个任意字符,它常用来限制表达式的字符长度语句:

SELECT * FROM [user] WHERE u_name LIKE ‘_三_’————只找出“唐三藏”这样u_name为三个字且中间一个字是“三”的;

 c、[ ]:表示括号内所列字符中的一个(类似正则表达式)。指定一个字符、字符串或范围,要求所匹配对象为它们中的任一个。

SELECT * FROM [user] WHERE u_name LIKE ‘[张李王]三’———————将找出“张三”、“李三”、“王三”(而不是“张李王三”);

 d、[^ ] :表示不在括号所列之内的单个字符。其取值和 [] 相同,但它要求所匹配对象为指定字符以外的任一个字符。

SELECT * FROM [user] WHERE u_name LIKE ‘[^张李王]三’———-将找出不姓“张”、“李”、“王”的“赵三”、“孙三”等;

由于通配符的缘故,导致我们查询特殊字符“%”、“_”、“[”的语句无法正常实现,而把特殊字符用“[ ]”括起便可正常查询

二、Datasource和DataBind

a、通常使用DataSource属性进行数据源绑定的控件为列表控件(连接到数据源并把来自数据源的数据显示出来的Web服务器控件),列表控件有:CheckBoxList、DropDownList、ListBox、RadioButtonList、GridView、Datalist、Repeater等。

b、在为.aspx页上的对象设置了特定数据源之后,必须将数据绑定到这些数据源上。可以使用“Page.DataBind()”或“控件.DataBind()”方法将数据绑定到数据源上。

c、注意:使用DataSource数据源后,还需要显示调用列表控件的DataBind()方法来连接DataSet、DataReader等数据源。从而执行数据绑定和解析数据绑定表达式。

————————

Various fuzzy queries of SQL statements

General fuzzy statements are as follows: select field from table where a field like condition

For conditions, SQL provides four matching modes:

a. %: represents any 0 or more characters. It can match characters of any type and length. In some cases, if it is Chinese, please use two percent signs (%%).

SELECT * FROM [user] WHERE u_ Name like ‘% three%’ —– will put U_ The name is “Zhang San”, “Zhang maosan”, “three legged cat”, “Tang Sanzang”, etc. all the records with “three” can be found

b._: Represents any single character. Matches a single arbitrary character, which is often used to limit the character length of an expression:

SELECT * FROM [user] WHERE u_ name LIKE ‘_ III. ‘———— Only “Tang Sanzang” is found u_ Name is three words and the middle word is “three”;

c. []: represents one of the characters listed in parentheses (similar to regular expression). Specify a character, string, or range that requires the matching object to be any of them.

SELECT * FROM [user] WHERE u_ Name like ‘[Zhang Li Wang] San’ —————- find out “Zhang San”, “Li San” and “Wang San” (instead of “Zhang Li Wang San”);

d. [^]: indicates a single character not listed in parentheses. Its value is the same as [], but it requires the matched object to be any character other than the specified character.

SELECT * FROM [user] WHERE u_ Name like ‘[^ Zhang, Li, Wang] San’ ———– find out “Zhao San” and “Sun San” who are not surnamed “Zhang”, “Li” and “Wang”;

Because of wildcards, we cannot query the special characters “%”, “” and “[” normally, but we can query normally by enclosing the special characters with “[]”

二、Datasource和DataBind

a. Generally, the controls that use the datasource property for data source binding are list controls (web server controls that connect to the data source and display the data from the data source). List controls include checkboxlist, dropdownlist, listbox, RadioButtonList, GridView, datalist, repeater, etc.

b. After you set up specific data sources for objects on. ASPX pages, you must bind data to these data sources. You can use the “page. Databind()” or “control. Databind()” methods to bind data to a data source.

c. Note: after using the datasource data source, you also need to display and call the databind () method of the list control to connect the dataset, datareader and other data sources. This performs data binding and parses data binding expressions.