欢迎来到千学网!
您现在的位置:首页 > 实用文 > 其他范文

用ADO对Excel的数据查询数据库教程

时间:2022-12-03 09:34:58 其他范文 收藏本文 下载本文

以下是小编整理的用ADO对Excel的数据查询数据库教程,本文共5篇,希望能够帮助到大家。

用ADO对Excel的数据查询数据库教程

篇1:用ADO对Excel的数据查询数据库教程

ado|excel|数据

ASP对Excel的基本操作之查询数据

Execl97//xp是MS Office办公软件的成员之一,在企业级应用当中,我们往往需要对Execl进行操作,如读取Execl里面的数据、往Execl里插入数据等。

一、操作Execl要注意的事项:

1、 服务器端Office的配置

以MS Windows2000+IIS为例,要在服务器端安装有MS Office的成员之一Execl,Office的版本没有特殊要求。

2、 服务器端分布式COM的配置

执行“ DCOMCNFG”命令,选择“应用程序”页的“Microsoft Execl 应用程序”―>“属性”―>“安全性”―>三个选项都选“使用自定义访问权限”,添加“Everyone”权限。

二、首先,先将利用ASP读取Execl的数据(不建立DSN):

我们可以整个.xsl文件看作是一个数据库,sheet1、sheet2等分别看成一个独立的表,把A1、B1、C1、…N1看作表的字段。

--建立连接对象实例ExeclConn

Set ExeclConn=Server.CreateObject(“ADODB.Connection”)

--利用Open 方法打开数据库

StrConn=“Driver={Microsoft Excel Driver (*.xls)};”&_

“DriverId=790; DBQ=”& Server.MapPath(“xls文件名”)

conn.Open StrConn

--建立数据集对象Rs并查询数据

Set Rs = Server.CreateObject(“ADODB.Recordset”)

Sql=“select * from [Sheet1$]”

rs.Open Sql,conn,2,2

具体例子:

1、建立一个表Sheet1(数据库名为Students)

StudentID

姓 名

语 文

数 学

物 理

化 学

地 理

1

李雪青

83

84

76

95

66

2

冯江

87

96

82

100

81

3

吴小霞

76

43

37

60

82

4

邹亚汇

80

77

63

71

63

5

蔡海飞

89

63

92

86

67

2、查询并显示表Sheet1内容的代码

<%

Dim conn

Dim StrConn

Dim rs

Dim Sql

Set conn=Server.CreateObject(“ADODB.Connection”)

StrConn=“Driver={Microsoft Excel Driver (*.xls)};”&_

“DriverId=790; DBQ=”& Server.MapPath(“Students.xls”)

conn.Open StrConn

Set rs = Server.CreateObject(“ADODB.Recordset”)

Sql=“select * from [Sheet1$]”

rs.Open Sql,conn,2,2

%>

<%

for i=0 to rs.Fields.Count-1

%>

<%=rs(i).Name%>

<%

next

%>

<%

do while Not rs.EOF

%>

<%

for i=0 to rs.Fields.Count-1

%>

<%=rs(i)%>

<%

next

%>

<%

rs.MoveNext

Loop

rs.close

set rs=nothing

StrConn.close

set StrConn=nothing

%>

3、运行结果

篇2:数据查询SELECT语句数据库教程

数据库是为更方便有效地管理信息而存在的人们,希望数据库可以随时提供所需要的数据信息,

数据查询SELECT语句数据库教程

。因此,对用户来说,数据查询是数据

库最重要的功能。本章将讲述数据查询的实现方法。

在数据库中,数据查询是通过SELECT 语句来完成的。SELECT 语句可以从数据库中按用户要求检索数据,并将查询结果以表格的形式返回。我们在“Transact-SQL 语言”章节及前面的章节中已经初步接触到了SELECT 语句的一些用法,在本章中将分类讲述其具体用法。

本节讲述SELECT 语句完整的锓结构U馐且桓龇浅H叱ぁ⒖菰锏墓程。读者? 以跳过本节,从第二节开始阅读,而将本节作为理解、编写查询语句的语法参考资料。 SELECT 语句完整的语法结构如下:

SELECT statement ::=

[ ORDER BY { order_by_expression | column_position [ ASC | DESC ] } [,...n] ]

[ COMPUTE { { AVG | COUNT | MAX | MIN | SUM } (expression) } [,...n]

[ BY expression [,...n] ] ]

[ FOR { BROWSE | XML { RAW | AUTO | EXPLICIT }

[ , XMLDATA ]

[ , ELEMENTS ]

[ , BINARY base64 ] }

[ OPTION ([,...n]) ]

::=

{ | () }

[UNION [ALL] ) [...n] ]

::=

SELECT [ ALL | DISTINCT ]

[ {TOP integer | TOP integer PERCENT} [ WITH TIES] ]

[ INTO new_table ]

[ FROM {} [,...n] ]

[ WHERE ]

[ GROUP BY [ALL] group_by_expression [,...n]

[ WITH { CUBE | ROLLUP } ] ]

[ HAVING ]

由于SELECT 语句特别复杂,上述结构还不能完全说明其用法,因此我们将它拆分为若干部分来讲述。

10.1.1 SELECT 子句

SELECT 子句指定需要通过查询返回的表的列,其语法如下:

SELECT [ ALL | DISTINCT ]

[ TOP n [PERCENT] [ WITH TIES] ]

::=

{ *

| { table_name | view_name | table_alias }.*

| { column_name | expression | IDENTITYCOL | ROWGUIDCOL }

[ [AS] column_alias ]

| column_alias = expression

} [,...n]

各参数说明如下:

ALL

指明查询结果中可以显示值相同的列。ALL 是系统默认的。

DISTINCT

指明查询结果中如果有值相同的列,则只显示其中的一列。对DISTINCT 选项来说, Null 值被认为是相同的值。

TOP n [PERCENT]

指定返回查询结果的前n 行数据。如果PERCENT 关键字指定的话,则返回查询结果的前百分之n 行数据。

WITH TIES

此选项只能在使用了ORDER BY 子句后才能使用当指定此项时,除了返回由TOP n (PERCENT) 指定的数据行外,还要返回与TOP n (PERCENT) 返回的最后一行记录中由ORDER BY 子句指定的列的列值相同的数据行。

select_list

select_list 是所要查询的表的列的集合,多个列之间用逗号分开。

* 通配符,返回所有对象的所有列。

table_name | view_name | table_alias.*

限制通配符*的作用范围。凡是带*的项,均返回其中所有的列。

column_name

指定返回的列名

expression

表达式可以为列名、常量、函数或它们的组合。

IDENTITYCOL

返回IDENTITY 列。如果FROM 子句中有多个表含有IDENTITY 列,则在IDENTTYCOL 选项前必须加上表名,如Table1.IDENTITYCOL。

ROWGUIDCOL

返回表的ROWGUIDCOL 列。同IDENTITYCOL 选项相同,当要指定多个ROWGUIDCOL 列时,选项前必须加上表名,如Table1. ROWGUIDCOL。

column_alias

在返回的查询结果中用此别名替代列的原名。column_alias 可用于ORDER BY 子句,但不能用于WHERE GROUP BY 或HAVING 子句如果查询是游标声明命令DECLARE CURSOR 的一部分,则column_alias 还不能用于FOR UPDATE 子句(有关游标的介绍请参见“游标和视图”章节)。

10.1.2 INTO 子句

INTO 子句用于把查询结果存放到一个新建的表中。SELECT...INTO 句式不能与COMPUTE 子句一起使用。其语法如下:

INTO new_table

参数new_table 指定了新建的表的名称。新表的列由SELECT 子句中指定的列构成,新表中的数据行是由WHERE 子句指定的。但如果SELECT 子句中指定了计算列,在新表中对应的列则不是计算列,而是一个实际存储在表中的列,其中的数据由执行SELECT...INTO 语句时计算得出。如果数据库的“Select into/bulk copy” 选项设置为“True/On”,则可以用INTO 子句创建表和临时表,反之,则只能创建临时表。

10.1.3 FROM 子句

FROM 子句指定需要进行数据查询的表。只要SELECT 子句中有要查询的列,就必须使用FROM 子句。其语法如下:

FROM {} [,...n]

::=

table_name [ [AS] table_alias ] [ WITH ( [,...n]) ]

| view_name [ [AS] table_alias ]

| rowset_function [ [AS] table_alias ]

| OPENXML

| derived_table [AS] table_alias [ (column_alias [,...n] ) ]

|

::=

ON

| CROSS JOIN

|

::=

[ INNER | { { LEFT | RIGHT | FULL } [OUTER] } ]

[ ]

JOIN

各参数说明如下:

table_source

指明SELECT 语句要用到的表、视图等数据源。

table_name [ [AS] table_alias ]

指明表名和表的别名。

view_name [ [AS] table_alias ]

指明视图名称和视图的别名。

rowset_function [ [AS] table_alias ]

指明行统计函数和统计列的名称。

OPENXML

提供一个XML 文档的行集合视图。

WITH ([,...n])

指定一个或多个表提示。通常SQL Server 的查询优化器会自动选取最优执行计划,除非是特别有经验的用户,否则最好不用此选项。关于表提示table_hint 的设,定请参见下一章的“删除数据”部分。

derived_table [AS] table_alias

指定一个子查询,从数据库中返回数据行。

column_alias

指明列的别名,用以替换查询结果中的列名。

joined_table

指定由连接查询生成的查询结果。有关连接与连接查询的介绍参见本章的相关章节。

join_type

指定连接查询操作的类型。

INNER

指定返回两个表中所有匹配的行。如果没有join_type 选项,此选项就为系统默认。

LEFT [OUTER]

返回连接查询左边的表中所有的相应记录,而右表中对应于左表无记录的部分,用NULL 值表示。

RIGHT [OUTER]

返回连接查询右边的表中所有的相应记录,而左表中对应于右表无记录的部分,用NULL 值表示。

FULL [OUTER]

返回连接的两个表中的所有记录。无对应记录的部分用NULL 值表示。

join_hint

指定一个连接提示或运算法则。如果指定了此选项,则INNER LEFT RIGHT 或FULL选项必须明确指定。通常SQL Server 的查询优化器会自动选取最优执行计划,除非是特别有经验的用户,否则最好不用此选项。

join_hint 的语法如下:

::= { LOOP | HASH | MERGE | REMOTE }

其中LOOP | HASH | MERGE 选项指定查询优化器中的连接是循环、散列或合并的。REMOTE 选项指定连接操作由右边的表完成。当左表的数据行少于右表,才能使用REMOTE 选项。当左表和右表都是本地表时,此选项不必使用。

JOIN

指明特定的表或视图将要被连接。

ON

指定连接的条件。

CROSS JOIN

返回两个表交叉查询的结果。10.1.4 WHERE 子句

WHERE 子句指定数据检索的条件,以限制返回的数据行。其语法如下:

WHERE |

::=

column_name { *= | =* } column_name

各参数说明如下:

search_condition

通过由谓词构成的条件来限制返回的查询结果,

old_outer_join

指定一个外连接。此选项是不标准的,但使用方便。它用“*=” 操作符表示左连接,用“=*” 操作符表示右连接。此选项与在FROM 子句中指定外连接都是可行的方法,但二者只能择其一。

注意:如果在WHERE子句中指定一个值为FALSE的条件,则可以用SELECT...INTO语句来创建一个表名不同,但结构和数据类型均和原表相同的表。

10.1.5 GROUP BY 子句

GROUP BY 子句指定查询结果的分组条件。其语法如下;

GROUP BY [ALL] group_by_expression [,...n]

[ WITH { CUBE | ROLLUP } ]

各参数说明如下:

ALL

返回所有可能的查询结果组合,即使此组合中没有任何满足WHERE 子句的数据。分组的统计列如果不满足查询条件,则将由NULL 值构成其数据。ALL 选项不能与CUBE或ROLLUP 选项同时使用。

GROUP BY ALL is not supported in queries that access remote tables.

group_by_expression

指明分组条件。group_by_expression 通常是一个列名,但不能是列的别名。数据类型为TEXT、NTEXT、IMAGE 或BIT 类型的列不能作为分组条件。

CUBE

除了返回由GROUP BY 子句指定的列外,还返回按组统计的行。返回的结果先按分组的第一个条件列排序显示,再按第二个条件列排序显示以此类推。统计行包括了GROUPBY 子句指定的列的各种组合的数据统计。

ROLLUP

与CUBE 不同的是,此选项对GROUP BY 子句中的列顺序敏感,它只返回第一个分组条件指定的列的统计行。改变列的顺序会使返回的结果的行数发生变化。

使用Distinct选项的统计函数,如AVG(DISTINCT column_name)、COUNT(DISTINCT column_name)、和SUM(DISTINCT column_name)等,不能在使用CUBE或ROLLUP选项时使用。

10.1.6 HAVING 子句

HAVING 子句指定分组搜索条件。HAVING 子句通常与GROUP BY 子句一起使用。TEXT、NTEXT 和IMAGE 数据类型不能用于HAVING 子句。其语法如下:

HAVING

HAVING 子句与WHERE 子句很相似,其区别在于其作用的对象不同。WHERE 子句作用于表和视图,HAVING 子句作用于组。

10.1.7 UNION 操作符

UNION 操作符将两个或两个以上的查询结果合并为一个结果集。它与使用连接查询合并两个表的列是不同的。使用UNION 操作符合并查询结果需要遵循两个基本规则:

列的数目和顺序在所有查询中必须是一致的;

数据类型必须兼容。

其语法如下:

| ()

UNION [ALL]

)

[UNION [ALL] ) [...n] ]

各参数说明如下:

| ()

指明查询的详细说明或查询表达式。

UNION

合并操作符。

ALL

合并所有数据行到结果中,包括值重复的数据行。如果不指定此选项,则重复的数据行只显示一行。

10.1.8 ORDER BY 子句

ORDER BY 子句指定查询结果的排序方式。其语法如下:

ORDER BY {order_by_expression [ ASC | DESC ] } [,...n]

各参数说明如下:

order_by_expression

指定排序的规则。order_by_expression 可以是表或视图的列的名称或别名。如果SELECT 语句中没有使用DISTINCT 选项或UNION 操作符。那么ORDER BY 子句中可以包含select list 中没有出现的列名。或别名ORDER BY 子句中也不能使用TEXT、NTEXT 和 IMAGE 数据类型。

ASC

指明查询结果按升序排列。这是系统默认值。

DESC

指明查询结果按降序排列。

注意:Null值被作为最小的值。

10.1.9 COMPUTE 子句

COMPUTE 子句在查询结果的末尾生成一个汇总数据行。其语法如下:

COMPUTE

{ { AVG | COUNT | MAX | MIN | STDEV | STDEVP |VAR | VARP | SUM }

(expression) } [,...n]

[ BY expression [,...n] ]

各参数说明如下:

AVG | COUNT | MAX | MIN | STDEV | STDEVP | VAR | VARP | SUM以上参数与对应的函数有相同的含义。这些函数均会忽略NULL 值,且DISTINCT选项不能在此使用。

expression

指定需要统计的列的名称。此列必须包含于SELECT 列表中,且不能用别名。COMPUTE子句中也不能使用TEXT、NTEXT 和IMAGE 数据类型。

BY expression

在查询结果中生成分类统计的行。如果使用此选,项则必须同时使用ORDER BY 子句。expression 是对应的ORDER BY 子句中的order_by_expression 的子集或全集。

注意:在SELECT子句中使用统计函数,会覆盖COMPUTE子句中的相应选项。在SELECTINTO语句中不能使用COMPUTE子句。

10.1.10 FOR BROWSE 子句

FOR BROWSE 子句用于读取另外的用户正在进行添加、删除或更新记录的表。其语法如下:

FOR { BROWSE | XML { RAW | AUTO | EXPLICIT }

[ , XMLDATA ]

[ , ELEMENTS ]

[ , BINARY base64 ]

}

各参数说明如下:

BROWSE

BROWSE 选项指明当查看在使用DB-Library 的客户机应用程序中的数据时,可以更新数据。

使用此子句时对所操作的表有一些限制:

表必须包含一个timestamp 类型的时间标识列;

表必须有一个惟一索引。

注意:

在SELECT语句中:FOR BROWSE子句必须是SELECT语句的最后子句;FOR BROWSE子句不能与UNION操作符同时使用;FOR BROWSE子句不能与表提示HOLDLOCK选项同时使用。

XML

XML 选项指明查询结果以XML 文档模式返回XML。 模式分为RAW、AUTO、EXPLICIT 三种。

RAW

将查询结果每一行转换为以一个普通标识符作为元素标识XML 文档。

AUTO

以简单嵌套的XML 树方式返回查询结果。

EXPLICIT

指定查询结果的XML 树的形式被明确定义的。

XMLDATA

返回概要信息。它是附加在文档上返回的。

ELEMENTS

指明列将以子元素的方式返回。

BINARY base 64

指定查询返回的以base64 格式编码的二进制数据。

10.1.11 OPTION 子句

OPTION 子句用于指定在整个查询过程中的查询提示(Query Hint)。通常,用户不必使用OPTION 子句,因为查询优化器会自动选择一个最佳的查询计划。OPTION 子句必须由最外层的主查询来指定。各查询提示之间应使用逗号隔开。其语法如下:

OPTION ([,...n] )

::=

{ { HASH | ORDER } GROUP

| { CONCAT | HASH | MERGE } UNION

| { LOOP | MERGE | HASH } JOIN

| FAST number_rows

| FORCE ORDER

| MAXDOP number

| ROBUST PLAN

| KEEP PLAN

| KEEPFIXED PLAN

| EXPAND VIEWS

}

各参数说明如下:

{HASH | ORDER} GROUP

指定在GROUP BY 或COMPUTE 子句中指定的查询使用散列法或排序法。所谓散列法是指为存储和检索数据项或数据,把搜索关键字转换为一个地址的一种方法。该方法常作为数据集内的记录的一种算法,可以使记录分组均匀,减少搜索时间。

{MERGE | HASH | CONCAT} UNION

指定所有的UNION 操作符采用合并(Merge)、散列(Hash) 或连接(Concatenate)的方法执行操作。如果指定了多个UNION 提示,查询优化器会挑选一个最佳的提示方案。

{LOOP | MERGE | HASH |} JOIN

指定查询过程中的所有连接操作采取循环连接(Loop Join)、合并连接(Merge Join)或散列连接(Hash Join) 的方法。如果指定了多个JOIN 提示,查询优化器会挑选一个最佳的提示方案。

FAST number_rows

指定查询优化只用于迅速返回前number_rows 行数据,在number_rows 行以后的数据采用原查询方法。

FORCE ORDER

指定在查询语法中说明的连接顺序在查询优化的过程中保持不变。

MAXDOP number

忽略由Sp_configure 设定的针对查询的最大并行线程数目。

ROBUST PLAN

强制查询优化器尝试使用最大行容量的计划。

KEEP PLAN

强制查询优化器放松重新编译查询的阈值。指定此选项可以让一个表被多次更新而不必频繁地重新编译查询。

KEEPFIXED PLAN

强制查询优化器不重新编译查询。这样只有当表的概要改变或执行Sp_recompile 存储过程时,才会重新编译查询。

EXPAND VIEWS

扩展索引化视图(当一个视图的名称在查询文本中被视图定义替换时称这个视图被扩展了),并且查询优化器不再将索引化视图作为查询的某部分的替代品。如果视图使用了WITH (NOEXPAND) 说明,则不能被扩展。注意:SELECT语句中各子句的排列次序是很重要的,子句必须依相应的次序来使用。

当用SELECT命令读取TEXT和IMAGE类型数据时,一次所能读取的数据受限于@@TE-XTSIZE全局变量的值。

可以用SET TEXTSIZE命令来更改它。@@TEXTSIZE的初始值为4K,最大为231-1(2,147,483,647)个字节。

篇3:用SQL进行函数查询数据库教程

Oracle 9i提供了很多函数可以用来辅助数据查询,

用SQL进行函数查询数据库教程

。接下来我们介绍常用的函数功能及使用方法。

4.5.1 【ceil】函数

在【命令编辑区】输入“select mgr, mgr/100,ceil(mgr/100) from scott.emp;”,然后单击【执行】按钮,出现如图4.29所示的结果。

【参见光盘文件】:\第4章\4.5\451.sql。

【ceil】函数用法:ceil(n),取大于扔谑值n的最小整数。

4.5.2 【floor】函数

在【命令编辑区】输入“select mgr, mgr/100,floor(mgr/100) from scott.emp;”,然后单击【执行】按钮,出现如图4.30所示的结果。

【参见光盘文件】:\第4章\4.5\452.sql。

【floor】函数用法:floor(n),取小于等于数值n的最大整数。

4.5.3 【mod】函数

在【命令编辑区】输入“select mgr, mod(mgr,1000), mod(mgr,100), mod(mgr,10) from scott.emp;”,然后单击【执行】按钮,出现如图4.31所示的结果。

【参见光盘文件】:\第4章\4.5\453.sql。

【mod】函数用法:mod(m,n),取m整除n后的余数。

4.5.4 【power】函数

在【命令编辑区】输入“select mgr, power(mgr,2),power(mgr,3) from scott.emp;”,然后单击【执行】按钮,出现如图4.32所示的结果。

【参见光盘文件】:\第4章\4.5\454.sql。

【power】函数用法:power(m,n),取m的n次方。

4.5.5 【round】函数

在【命令编辑区】输入“select mgr, round(mgr/100,2),round(mgr/1000,2) from scott.emp;”,然后单击【执行】按钮,出现如图4.33所示的结果。

【参见光盘文件】:\第4章\4.5\455.sql。

【round】函数用法:round(m,n),四舍五入,保留n位。

4.5.6 【sign】函数

在【命令编辑区】输入“select mgr, mgr-7800,sign(mgr-7800) from scott.emp;”,然后单击【执行】按钮,出现如图4.34所示的结果,

【参见光盘文件】:\第4章\4.5\456.sql。

【sign】函数用法:sign(n)。n>0,取1;n=0,取0;n<0,取-1。

4.5.7 【avg】函数

在【命令编辑区】输入“select avg(mgr)平均薪水 from scott.emp;”,然后单击【执行】按钮,出现如图4.35所示的结果。

【参见光盘文件】:\第4章\4.5\457.sql。

【avg】函数用法:avg(字段名),求平均值。要求字段为数值型。

4.5.8 【count】函数

(1)在【命令编辑区】输入“select count(*) 记录总数 from scott.emp;”,然后单击【执行】按钮,出现如图4.36所示的结果。

【参见光盘文件】:\第4章\4.5\458-1.sql。

(2)在【命令编辑区】输入“select count(distinct job ) 工作类别总数 from scott.emp;”,然后单击【执行】按钮,出现如图4.37所示的结果。

【参见光盘文件】:\第4章\4.5\458-2.sql。

【count】函数用法:count(字段名)或count(*),统计总数。

4.5.9 【min】函数

在【命令编辑区】输入“select min(sal) 最少薪水 from scott.emp;”,然后单击【执行】按钮,出现如图4.38所示的结果。

【参见光盘文件】:\第4章\4.5\459.sql。

【min】函数用法:min(字段名),计算数值型字段最小数。

4.5.10 【max】函数

在【命令编辑区】输入“select max(sal) 最高薪水 from scott.emp;”,然后单击【执行】按钮,出现如图4.39所示的结果。

【参见光盘文件】:\第4章\4.5\4510.sql。

【max】函数用法:max(字段名),计算数值型字段最大数。

4.5.11 【sum】函数

在【命令编辑区】输入“select sum(sal) 薪水总和 from scott.emp;”,然后单击【执行】按钮,出现如图4.40所示的结果。

【参见光盘文件】:\第4章\4.5\4511.sql。

【sum】函数用法:sum(字段名),计算数值型字段总和。

通过上面4类查询实例的学习,读者可以举一反三,灵活运用。用SQL进行数据的查询就介绍到这里,下面学习如何录入数据。

篇4:一个供查询用的datawindow数据库教程

window

主要供以grid方式展示查询数据使用, 包括以下几个功能:

1、点击列头排序(可选);

2、时候,自动用微帮助展示(可选);

3、数据库错误时中文提示;

包括以下对象(按顺序导入即可):

1、gf_dberrormsg

global type gf_dberrormsg from function_objectend type

forward prototypesglobal function integer gf_dberrormsg (long sqldbcode, string sqlerrtext, long row, string as_ty)end prototypes

global function integer gf_dberrormsg (long sqldbcode, string sqlerrtext, long row, string as_ty);//有关数据窗口的错误:Choose Case SQLDBCode Case 1400  If as_ty = “freeform” Then   MessageBox(“提示信息” , “请查找空项,并填入内容,才能保存!”)  Else   MessageBox(“提示信息”,“请查找第”+String(row)+“行空列,并填入内容,才能保存!”)  End If Case 1  If as_ty = “freeform” Then   MessageBox(“提示信息” , “此项记录已经存在,不能重复!”)  Else   MessageBox(“提示信息”,“请查重复行第”+String(row)+“行,修改某列或删除重复行,才能保存!”)  End If Case 3114  MessageBox(“提示信息”,“没有连接数据库,建议重新运行应用程序!”) Case -193  If as_ty = “freeform” Then   MessageBox(“提示信息” , “此项记录已经存在,不能重复!”)  Else   MessageBox(“提示信息”,“请查重复行第”+String(row)+“行,修改某列或删除重复行,才能保存!”)  End If Case -195 // Required value is NULL.  If as_ty = “freeform” Then   MessageBox(“提示信息” , “请查找空项,并填入内容,才能保存!”)  Else   MessageBox(“提示信息”,“请查找第”+String(row)+“行空列,并填入内容,才能保存!”)  End If Case -3  MessageBox(“注意信息”,“原数据已被其它用户修改,请重新检索后再保存!”) Case 2601  MessageBox(“注意信息”,“主键记录重复,不能保存!”) Case 233  MessageBox(“注意信息”,“主键记录为空,不能保存!”) Case 1105 //Sybase??  MessageBox(“注意信息”,“数据库日志满,请通知系统管理员清日志!”) Case 2627  MessageBox(“注意信息”,“您新增的记录已存在,插入失败! 也许是网络冲突,请您稍后再做此项操作,”) Case -932  MessageBox(“注意信息”,“请检查网络是否正常工作!”) Case 10004  MessageBox(“注意信息”,“请检查数据库是否正常工作!”) Case 999  MessageBox(“注意信息”,“请检查服务器是否正常工作!”) Case Else  MessageBox(“数据库提示信息:”,“出错行:” + String(row) + “, 出错信息:” + SQLErrText+“SQLDBCode:”+string(SQLDBCode))End Choose

Return 1

end function

2、n_cst_dwsrv_gridsort

forwardglobal type n_cst_dwsrv_gridsort from nonvisualobjectend typeend forward

global type n_cst_dwsrv_gridsort from nonvisualobjectevent type long ue_lbuttondown ( unsignedlong flags, integer xpos, integer ypos )event type long ue_lbuttonup ( unsignedlong flags, integer xpos, integer ypos )end typeglobal n_cst_dwsrv_gridsort n_cst_dwsrv_gridsort

type prototypesFunction ULong SetCapture(ULong hWnd) Library “USER32.DLL”Function Boolean ReleaseCapture Library “USER32.DLL”

end prototypes

type variablesPrivate: DataWindow idw_requestor string i_str_oldcolumn //上次点击排序的列名 string i_str_newcolumn //本次点击排序的列名 string i_str_arrowname //排序用的小三角符号名 string i_str_sort='A' //上次排序是升序(A)还是降序(B) string i_str_flag='0' //是否已执行正确的鼠标按下事件(0-否,1-是)

end variables

forward prototypespublic function integer of_setrequestor (datawindow adw_requestor)end prototypes

event type long ue_lbuttondown(unsignedlong flags, integer xpos, integer ypos);String str_band,str_object,str_title,str_columnint li_x

str_band = idw_requestor.GetBandAtPointer() //得到当前鼠标所指对象所在的带区str_band = Left(str_band,(Pos(str_band,'~t') - 1))If str_band 'header' Then Return 0 //单击非头区,退出str_object = idw_requestor.GetObjectAtPointer() //得到当前鼠标所指对象名str_object = Left(str_object,(Pos(str_object,'~t') - 1))If str_object = '' Or IsNull(str_object) Then Return 0 //未得到,退出If Right(str_object,4) = '_lag' Then //点击的是小三角符号对象,说明上次点击过该列 str_title = Left(str_object,(Len(str_object) - 4))Else //头一次点击该列 str_title = str_objectEnd If//得到列对象名(默认为列名_t为列标题)str_column = Left(str_title,(Len(str_title) - 2))//判断该名称是否为列名字If idw_requestor.Describe(str_column+“.band”) = '!' Then Return 0//非是列名,即列标题不是按正常规律起名的。

//列的交接处,可能出现调整列宽度状态li_x=integer(idw_requestor.Describe(str_object+“.X”))if String(idw_requestor.Object.DataWindow.HorizontalScrollSplit)='0' then if xpos+integer(idw_requestor.Object.DataWindow.HorizontalScrollPosition)- li_x<=6 then  return 0 end ifend if

i_str_newcolumn = str_column //得到当前单击的列idw_requestor.Modify(str_title+“.border='5'”) //设置下凹动画效果i_str_flag = '1' //已启动单击事件//设置鼠标捕获SetCapture(Handle(idw_requestor)) //将鼠标的动作转移给指定的DW窗口Return 0

end event

event type long ue_lbuttonup(unsignedlong flags, integer xpos, integer ypos);String str_title,str_object,str_tmp,str_column,str_sortLong lng_posy,lng_left,lng_top,lng_right,lng_bottom

lng_posy = yposstr_object = idw_requestor.GetObjectAtPointer()ReleaseCapture() //必须先释放鼠标否则该鼠标动作将一直被数据窗口捕获

str_title = i_str_newcolumn+'_t'If i_str_flag = '1' Then lng_left = Long(idw_requestor.Describe(str_title+“.x”)) lng_top = Long(idw_requestor.Describe(str_title+“.y”)) lng_right = lng_left+Long(idw_requestor.Describe(str_title+“.width”)) lng_bottom = lng_top+Long(idw_requestor.Describe(str_title+“.height”)) str_object = Left(str_object,(Pos(str_object,'~t') - 1)) If Not (str_object = '' Or IsNull(str_object)) Then //得到单击对象  If Right(str_object,4) = '_lag' Then //点击的是箭头对象,说明上次已点击过此列   str_tmp = Left(str_object,(Len(str_object) - 4))  Else //头一次点击该列   str_tmp = str_object  End If  If str_tmp = str_title Then //说明是在点击列上释放鼠标的   //判断是否上次点击该列,并排序   If i_str_oldcolumn = i_str_newcolumn Then //上次点击的也是此列    If i_str_sort = 'A' Then     str_sort = 'D'     str_tmp = '6'    Else     str_sort = 'A'     str_tmp = '5'    End If   Else //上次点击的不是此列    str_sort = 'A'    str_tmp = '5'   End If   //不管有没有全删除箭头对象   idw_requestor.Modify(“destroy ”+i_str_arrowname)   i_str_arrowname = str_title+'_lag' //生成新的箭头对象名=标题名_lag   str_tmp = 'create text(band=header alignment=“0” text=“'+str_tmp+'” border=“0” color=“16711680” x=“'+String(lng_left)+'” y=“'+String(lng_top)+'” height=“'+String(lng_bottom - lng_top)+'” width=“10” name='+i_str_arrowname+' visible=“1” font.face=“Webdings” font.height=“-12” font.weight=“400” font.family=“1” font.pitch=“2” font.charset=“2” background.mode=“1” background.color=“553648127” )'   idw_requestor.Modify(str_tmp)   str_tmp = i_str_newcolumn+' '+str_sort   idw_requestor.SetSort(str_tmp)   idw_requestor.Sort()   i_str_oldcolumn = i_str_newcolumn   i_str_newcolumn = ''   i_str_sort = str_sort  End If End IfEnd Ifidw_requestor.Modify(str_title+“.border='6'”)i_str_flag = '0'Return 0

end event

public function integer of_setrequestor (datawindow adw_requestor);If IsNull(adw_requestor) or Not IsValid(adw_requestor) Then Return -1End If

idw_Requestor = adw_RequestorReturn 1end function

on n_cst_dwsrv_gridsort.createcall super::createTriggerEvent( this, “constructor” )end on

on n_cst_dwsrv_gridsort.destroyTriggerEvent( this, “destructor” )call super::destroyend on

event constructor;//单击列标题对列进行排序end event

3、nvo_tooltips

forwardglobal type nvo_tooltips from nonvisualobjectend typetype point from structure within nvo_tooltipsend typetype msg from structure within nvo_tooltipsend typetype rect from structure within nvo_tooltipsend typetype toolinfo from structure within nvo_tooltipsend typeend forward

type point from structure long  x long  yend type

type msg from structure long  hwnd long  message long  wparam long  lparam long  time point  ptend type

type rect from structure long  left long  top long  right long  bottomend type

type toolinfo from structure long  cbsize long  uflags long  hwnd long  uid rect  rect long  hinstance string  lpsztextend type

global type nvo_tooltips from nonvisualobject autoinstantiateend type

type prototypes// ToolTips函数SubRoutine InitCommonControls() library “comctl32.dll”Function long CreateWindowExA(ulong dwExStyle, string ClassName, &    long WindowName, ulong dwStyle, ulong X, ulong Y, ulong nWidth, &    ulong nHeight, ulong hWndParent, ulong hMenu, ulong hInstance, &    ulong lpParam) library “user32.dll”Function integer DestroyWindow(long hWnd) library “user32.dll”Function integer ToolTipMsg(long hWnd, long uMsg, long wParam, &    REF TOOLINFO ToolInfo) library “user32.dll” Alias For “SendMessageA”Function integer RelayMsg(long hWnd, long uMsg, long wParam, &    REF MSG Msg) library “user32.dll” Alias For “SendMessageA”Function uLong SendMessageString( uLong hwnd, uLong Msg, uLong wParam, Ref String lpzString ) Library “user32.dll” Alias For “SendMessageA”FUNCTION ulong ShowWindow(ulong hwnd,ulong nCmdShow) LIBRARY “user32.dll”//内存管理函数//Function long LocalAlloc(long Flags, long Bytes) library “kernel32.dll”//Function long LocalFree(long MemHandle) library “kernel32.dll”//Function long lstrcpy(long Destination, string Source) library “kernel32.dll”

FUNCTION ulong IsWindowVisible(ulong hwnd) LIBRARY “user32.dll”end prototypes

type variables//私有常量Private:

//杂项常量CONSTANT string TOOLTIPS_CLASS = 'tooltips_class32'CONSTANT ulong CW_USEDEFAULT = 2147483648CONSTANT long WM_USER = 1024CONSTANT long WS_EX_TOPMOST = 8CONSTANT long WM_SETFONT = 48

// ToolTip MessagesConstant long TTM_ADDTOOL  = WM_USER + 4Constant long TTM_DELTOOL = WM_USER + 5Constant long TTM_NEWTOOLRECT = WM_USER + 6Constant long TTM_RELAYEVENT  = WM_USER + 7Constant long TTM_POPUP =WM_USER + 34 Constant long TTM_UPDATE= WM_USER + 29Constant long TTM_UPDATETIPTEXT = WM_USER + 12Constant long TTM_TRACKACTIVATE = WM_USER + 17Constant long TTM_TRACKPOSITION = WM_USER + 18Constant long TTM_SETMAXTIPWIDTH = 1048Constant long TTM_GETMAXTIPWIDTH = WM_USER + 25Constant long TTM_SETTIPBKCOLOR = WM_USER + 19Constant long TTM_SETTIPTEXTCOLOR = WM_USER + 20Constant long TTM_SETTITLEA = WM_USER + 32// Tooltip flagsConstant integer TTF_CENTERTIP  = 2Constant integer TTF_RTLREADING = 4Constant integer TTF_SUBCLASS  = 16Constant integer TTF_TRACK  = 32Constant integer TTF_ABSOLUTE  = 128Constant integer TTF_TRANSPARENT = 256Constant integer TTF_DI_SETITEM  = 32768Constant integer TTS_BALLOON = 64

// Title ConstantsConstant integer TTI_NONE = 0Constant integer TTI_INFO = 1Constant integer TTI_WARNING = 2Constant integer TTI_ERROR = 3//公共变量和常量Public:long hWndTT=0 // Tooltip control window handlelong ToolID = 1 // Tooltip internal ID

CONSTANT integer STYLE_NORMAL = 0CONSTANT integer STYLE_BALLOONTIP = 1integer TIPSTYLE

end variables

forward prototypespublic subroutine setfont (long hfont)public subroutine settipposition (integer x, integer y)public subroutine settrack (dragobject object, integer uid, boolean status)public subroutine updatetiprect (dragobject object, long uid, long left, long top, long right, long bottom)public function integer addtool (dragobject object, string tiptext, integer flags)public subroutine hidetip (dragobject controlobject)public subroutine settiptext (dragobject object, long uid, string tiptext)public subroutine setmaxwidth (long al_maxwidth)public function integer removetool (dragobject ado_object, integer ai_toolid)public subroutine settiptitle (integer ai_icon, string as_title)public subroutine settipbkcolor (long aul_color)public subroutine relaymsg (dragobject object)public function boolean tipvisible ()public subroutine relaymsg (dragobject object, long wordparm, integer longparm)end prototypes

public subroutine setfont (long hfont);//此函数用于设置ToolTips窗口的字体,代码如下:

Send(hWndTT,WM_SETFONT,hFont,1)

end subroutine

public subroutine settipposition (integer x, integer y);//此函数用于设置ToolTips的位置,代码如下:

Send(hWndTT,TTM_TRACKPOSITION,0,Long(X,Y))

end subroutine

public subroutine settrack (dragobject object, integer uid, boolean status);//此函数用于激活或取消ToolTips窗口设置新文本,代码如下://参数Status为True时激活,为False时取消

TOOLINFO ToolInfo

ToolInfo.cbSize = 40ToolInfo.hWnd = Handle(Object)ToolInfo.uID = uID

If Status Then ToolTipMsg(hWndTT,TTM_TRACKACTIVATE,1,ToolInfo)Else ToolTipMsg(hWndTT,TTM_TRACKACTIVATE,0,ToolInfo)End If

end subroutine

public subroutine updatetiprect (dragobject object, long uid, long left, long top, long right, long bottom);//此函数用于更新ToolTips的矩形框,代码如下:

TOOLINFO TOOLINFO

TOOLINFO.hWnd = Handle(Object)TOOLINFO.uID = uID

TOOLINFO.Rect.Left = LeftTOOLINFO.Rect.Top  = TopTOOLINFO.Rect.Right = RightTOOLINFO.Rect.Bottom = Bottom

ToolTipMsg(hWndTT,TTM_NEWTOOLRECT,0,TOOLINFO)

end subroutine

public function integer addtool (dragobject object, string tiptext, integer flags);//此函数用于注册要显示ToolTips的控制,代码如下:If hWndTT <= 0 Then If TIPSTYLE. = STYLE_BALLOONTIP Then  hWndTT = CreateWindowExA(WS_EX_TOPMOST,TOOLTIPS_CLASS,0, TTF_CENTERTIP+ TTS_BALLOON, &   CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, &   0, 0, Handle(GetApplication()),0) Else  hWndTT = CreateWindowExA(WS_EX_TOPMOST, TOOLTIPS_CLASS,0,TTF_CENTERTIP, &   CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, &   0, 0, Handle(GetApplication()),0) End IfEnd If

TOOLINFO TOOLINFO

TOOLINFO.cbSize = 40TOOLINFO.uFlags = FlagsTOOLINFO.hWnd = Handle(Object)TOOLINFO.hInstance = 0TOOLINFO.uID = ToolIDToolID++TOOLINFO.lpszText = tiptext//LStrCpy(ToolInfo.lpszText,Left(tiptext,80))

TOOLINFO.Rect.Left = 0TOOLINFO.Rect.Top = 0TOOLINFO.Rect.Right = UnitsToPixels(Object.Width,XUnitsToPixels!)TOOLINFO.Rect.Bottom = UnitsToPixels(Object.Height,YUnitsToPixels!)

If ToolTipMsg(hWndTT,TTM_ADDTOOL, 0, TOOLINFO) = 0 Then // MessageBox(“错误”,“不能注册控件!”,StopSign!,Ok!) //  LocalFree(ToolInfo.lpszText) //释放分配的内存 Return(-1)End If

//LocalFree(ToolInfo.lpszText) //释放分配的内存Return(ToolID - 1)

end function

public subroutine hidetip (dragobject controlobject);MSG MSGMSG.hWnd = Handle(ControlObject)MSG.Message = 513 // WM_LBUTTONDOWNMSG.WParam = Message.WordParmMSG.Lparam = Message.LongParm

RelayMsg(hWndTT,TTM_RELAYEVENT,0,MSG)

end subroutine

public subroutine settiptext (dragobject object, long uid, string tiptext);//此函数用于为ToolTips窗口设置新文本,代码如下:

TOOLINFO ToolInfo

ToolInfo.hWnd = Handle(Object)ToolInfo.uID = uIDToolInfo.lpszText = TipText

ToolTipMsg(hWndTT,TTM_UPDATETIPTEXT,0,ToolInfo)

end subroutine

public subroutine setmaxwidth (long al_maxwidth);/*****************************************************************************

Function:  of_setmaxwidth

Description: Sets the maximum tooltip width. If the text is longer it will      splitted over more than one line.

Returns:   (none)

Arguments:  Long  al_MaxWidth

Use:    Call to set the maximum width.

-------------------------------------------------------------------------------

Auteur: Aart Onkenhout

Revision History -------------------- Date   Version 15-05- 1.0  Initial version

******************************************************************************/

Send( hWndTT, TTM_SETMAXTIPWIDTH, 0, UnitsToPixels( al_MaxWidth, xUnitsToPixels! ) )

Returnend subroutine

public function integer removetool (dragobject ado_object, integer ai_toolid);/*****************************************************************************

Function:  of_removetool

Description: Unregisters a control within the tooltip control

Returns:   (none)

Arguments:  DragObject  ado_Object Object to unregister within the tooltip control      Integer   ai_ToolId Tool Id (returned by of_AddTool)

Use:

-------------------------------------------------------------------------------

Auteur: Aart Onkenhout

Revision History -------------------- Date   Version 29-06- 1.0  Initial version

******************************************************************************/

TOOLINFO TOOLINFOInteger li_Width, li_Height

TOOLINFO.cbSize = 40TOOLINFO.uFlags = 16 //Flags TOOLINFO.hWnd  = Handle( ado_Object )TOOLINFO.hInstance = 0 // Not used TOOLINFO.uID  = ai_ToolID

ToolTipMsg( hWndTT, TTM_DELTOOL, 0, TOOLINFO )

Return 1

end function

public subroutine settiptitle (integer ai_icon, string as_title);/*****************************************************************************

Function:  of_settiptitle

Description: Sets the title of the tooltip

Returns:   (none)

Arguments:  Integer  ai_Icon      Values:  TTI_NONE = 0          TTI_INFO = 1          TTI_WARNING = 2          TTI_ERROR = 3      String  as_Title

Use:    Call with the desired title and icon.

-------------------------------------------------------------------------------

Auteur: Aart Onkenhout

Revision History -------------------- Date   Version 10-05-2001 1.0  Initial version

******************************************************************************/

SendMessageString( hWndTT, TTM_SETTITLEA, ai_Icon, as_Title )end subroutine

public subroutine settipbkcolor (long aul_color);/*****************************************************************************

Function:  of_settipbkcolor

Description: Sets the backgroundcolor of the tooltip-window

Returns:   (none)

Arguments:  uLong  aul_Color

Use:    Call with the desired color

-------------------------------------------------------------------------------

Auteur: Aart Onkenhout

Revision History -------------------- Date   Version 10-05-2001 1.0  Initial version

******************************************************************************/

Send( hWndTT, TTM_SETTIPBKCOLOR,aul_color, 0 )end subroutine

public subroutine relaymsg (dragobject object);//此函数用于向显示ToolTips窗口发送控制消息,代码如下:MSG MSG

MSG.hWnd  = Handle(Object) // WM_MOUSEMOVEMSG.Message = 512MSG.WParam = Message.WordParmMSG.LParam = Message.LongParm

RelayMsg(hWndTT,TTM_RELAYEVENT,0,MSG)

end subroutine

public function boolean tipvisible ();If IsWindowVisible(HwndTT) >0 Then Return True

Return False

end function

public subroutine relaymsg (dragobject object, long wordparm, integer longparm);//此函数用于向显示ToolTips窗口发送控制消息,代码如下:MSG MSG

MSG.hWnd  = Handle(Object) // WM_MOUSEMOVEMSG.Message = 512MSG.WParam = WordParmMSG.LParam = LongParm

RelayMsg(hWndTT,TTM_RELAYEVENT,0,MSG)

end subroutine

on nvo_tooltips.createcall super::createTriggerEvent( this, “constructor” )end on

on nvo_tooltips.destroyTriggerEvent( this, “destructor” )call super::destroyend on

event constructor;//结构point用于传送坐标//结构msg用于传送消息//结构rect用于传送矩形框的位置//结构toolinfo用于传送与tooltips相关的消息

//用法///////////////////////////////////////////////////////////////定义实例变量://nca_ToolTips invo_ToolTip

//window open事件://注册要显示ToolTips的控制//invo_tooltip.AddTool(sle_userid,“请输入登录用户名”,0)//invo_tooltip.AddTool(sle_password,“请输入登录口令”,0)//需要提示的控件,在自定义ue_mousemove事件(pbm_mousemove)://invo_tooltip.RelayMsg(This)//////////////////////////////////////////////////////////////////

InitCommonControls()

end event

event destructor;if hWndTT>0 then DestroyWindow(hWndTT)end event

4、n_cst_dwsrv_autohint

forwardglobal type n_cst_dwsrv_autohint from nonvisualobjectend typetype logfont from structure within n_cst_dwsrv_autohintend typetype textsize from structure within n_cst_dwsrv_autohintend typeend forward

type logfont from structure long  lfHeight long  lfWidth long  lfEscapement long  lfOrientation long  lfWeight character  lfItalic character  lfUnderline character  lfStrikeOut character  lfCharSet character  lfOutPrecision character  lfClipPrecision character  lfQuality character  lfPitchAndFamily string  lfFaceNameend type

type textsize from structure long  l_cx long  l_cyend type

global type n_cst_dwsrv_autohint from nonvisualobjectevent type long ue_mousemove ( unsignedlong flags, integer xpos, integer ypos )event type long resize ( unsignedlong sizetype, integer newwidth, integer newheight )end typeglobal n_cst_dwsrv_autohint n_cst_dwsrv_autohint

type prototypesFUNCTION ulong GetDC(ulong hwnd) LIBRARY “user32.dll”FUNCTION ulong ReleaseDC(ulong hwnd,ulong hdc) LIBRARY “user32.dll”FUNCTION ulong SelectObject(ulong hdc,ulong hObject) LIBRARY “gdi32.dll”FUNCTION ulong DeleteObject(ulong hObject) LIBRARY “gdi32.dll”FUNCTION ulong CreateFontIndirect(ref LOGFONT lpLogFont) LIBRARY “gdi32.dll” ALIAS FOR “CreateFontIndirectA”FUNCTION ulong GetTextExtentExPoint(ulong hdc,ref string lpszStr,ulong cchString,ulong nMaxExtent,ref ulong lpnFit,ref ulong alpDx,ref textSIZE lpSize) LIBRARY “gdi32.dll” ALIAS FOR “GetTextExtentExPointA”FUNCTION ulong GetTextExtentPoint32(ulong hdc,ref string lpsz,ulong cbString,ref textSIZE lpSize) LIBRARY “gdi32.dll” ALIAS FOR “GetTextExtentPoint32A”Function long MulDiv (long nNumber, long nNumerator, long nDenominator) Library “KERNEL32.DLL”FUNCTION ulong GetDeviceCaps(ulong hdc,ulong nIndex) LIBRARY “gdi32.dll”

end prototypes

type variablesPrivate: DataWindow idw_requestor nvo_tooltips ToolTip String is_prior_dwo

end variables

forward prototypespublic function long of_gettextwidth (string as_colname, string as_text)public subroutine of_replacestring (ref string as_src, string as_oldstr, string as_newstr)public function integer of_setrequestor (datawindow adw_requestor)end prototypes

event type long ue_mousemove(unsignedlong flags, integer xpos, integer ypos);String ls_dwo,ls_col,ls_textLong ll_rowInt li_posls_dwo = idw_requestor.GetObjectAtPointer()

If is_prior_dwo = ls_dwo Then Return 0Else is_prior_dwo = ls_dwoEnd If

If Tooltip.tipvisible() or flags 0 Then Tooltip.hidetip(idw_requestor)end if

li_pos = Pos(ls_dwo, “~t”)If li_pos <= 0 Then Return 0

ls_col = Left (ls_dwo, li_pos - 1 )ll_row = Long(Mid(ls_dwo,li_pos + 1 ))

If idw_requestor.Describe(ls_col+“.Type”) “column” Then Return 0 //不是列对象

Long ll_width,ll_needWidth,ll_xString ls_editStyll_width = Long(idw_requestor.Describe(ls_col+“.Width”))ll_x = Long(idw_requestor.Describe(ls_col+“.x”))ls_editSty = idw_requestor.Describe(ls_col+“.Edit.Style”)

If ls_editSty = “editmask” Then //有掩码 Int li_colNum String ls_mask li_colNum = Integer(idw_requestor.Describe(ls_col+“.ID”)) ls_mask = idw_requestor.Describe(ls_col+“.EditMask.Mask”) If Left(idw_requestor.Describe(ls_col+“.Coltype”),4) = “char” Then //字符型掩码  //字符可以转化为数字(直接用string(s,“##”)得不到)  of_replaceString(ls_mask,“#”,“@”)  ls_text = String(idw_requestor.Object.Data[ll_row,li_colNum],ls_mask) Else //其它类型掩码  //// messagebox(“”,ls_mask)  ls_text = String(idw_requestor.Object.Data[ll_row,li_colNum],ls_mask) End IfElse //当前行列值(便于dddw,ddlb得到显示值) ls_text = idw_requestor.Describe(“Evaluate('LookUpDisplay(”+ls_col+“)',”+String(ll_row)+“)”)End If

//需要宽度ll_needWidth = of_getTextWidth(ls_col,ls_text)

If ls_editSty = “checkbox” Or ls_editSty = “radiobuttons” Then //这两种类型需要加个额外值 ll_needWidth+= 86End If

//列的宽度不够 或者 位于显示的最右列,只能显示一部分If ll_width < ll_needWidth Or & ll_x+ll_width >= idw_requestor.Width +Long(idw_requestor.Object.DataWindow.HorizontalScrollPosition) Then //修改Tip Tooltip.SetTipText( idw_requestor, Tooltip.ToolID - 1,ls_text) Tooltip.relaymsg(idw_requestor) Return 0End If

Return 0

end event

event type long resize(unsignedlong sizetype, integer newwidth, integer newheight);If sizetype 1 Then Tooltip.updatetiprect(idw_requestor,Tooltip.ToolID - 1 ,0,0,&  UnitsToPixels(idw_requestor.Width, XUnitsToPixels!),UnitsToPixels(idw_requestor.Height, YUnitsToPixels!) )End If

Return 0

end event

public function long of_gettextwidth (string as_colname, string as_text);//根据列名和文本,得到文本的显示宽度//得到字体相关信息Int li_charsetli_charset = Integer(idw_requestor.Describe(as_colName+“.Font.CharSet”))Int li_Escapementli_Escapement = Integer(idw_requestor.Describe(as_colName+“.Font.Escapement”))String ls_Facels_Face = idw_requestor.Describe(as_colName+“.Font.Face”)Int li_Familyli_Family = Integer(idw_requestor.Describe(as_colName+“.Font.Family”))Int li_heightli_height = Integer(idw_requestor.Describe(as_colName+“.Font.Height”))Int li_Italicli_Italic = Integer(idw_requestor.Describe(as_colName+“.Font.Italic”))Int li_Pitchli_Pitch = Integer(idw_requestor.Describe(as_colName+“.Font.Pitch”))Int li_Strikethroughli_Strikethrough = Integer(idw_requestor.Describe(as_colName+“.Font.Strikethrough”))Int li_Underlineli_Underline = Integer(idw_requestor.Describe(as_colName+“.Font.Underline”))Int li_Weightli_Weight = Integer(idw_requestor.Describe(as_colName+“.Font.Weight”))Int li_Widthli_Width = Integer(idw_requestor.Describe(as_colName+“.Font.Width”))

Long ll_newFont,ll_oldFont,ll_hdcLOGFONT   lst_Font

lst_Font.lfWeight = li_Weightlst_Font.lfWidth = li_WidthIf li_Italic = 1 Then lst_Font.lfItalic = Char(255)Else lst_Font.lfItalic = Char(0)End IfIf li_Underline = 1 Then lst_Font.lfUnderline = Char(1)Else lst_Font.lfUnderline = Char(0)End IfIf li_Strikethrough = 1 Then lst_Font.lfStrikeOut = Char(1)Else lst_Font.lfStrikeOut = Char(0)End If//DEFAULT_CHARSETlst_Font.lfCharSet = Char(li_charset)lst_Font.lfOutPrecision = Char(0)lst_Font.lfClipPrecision = Char(0)lst_Font.lfQuality = Char(0)lst_Font.lfPitchAndFamily = Char(0)lst_Font.lfFaceName = ls_Face

ll_hdc = getdc(Handle(idw_requestor))//以点为大小单位的字体转变成设备所需要的恰当的逻辑大小//LOGPIXELSY=90//muldiv : abs(li_Height)*getdevicecaps(ll_hdc,90)/72lst_Font.lfHeight = - muldiv(Abs(li_height),getdevicecaps(ll_hdc,90),72)//用指定的属性创建逻辑字体ll_newFont = CreateFontIndirect(lst_Font)//选入ll_oldFont = SelectObject(ll_hdc,ll_newFont)

TextSize lstr_Size//判断字串的大小GetTextExtentpoint32(ll_hdc, as_text, Len(as_text), lstr_Size )//恢复SelectObject(ll_hdc,ll_oldFont)//释放资源DeleteObject(ll_newFont)ReleaseDC(Handle(idw_requestor),ll_hdc)

//返回宽度(unit单位)Return PixelsToUnits(lstr_Size.l_cx,XPixelsToUnits!)

end function

public subroutine of_replacestring (ref string as_src, string as_oldstr, string as_newstr);Int start_pos = 0// Find the first occurrence of old_str.start_pos = Pos(as_src, as_oldstr)

// Only enter the loop if you find old_str.Do While start_pos >0 // Replace old_str with new_str. as_src = Replace(as_src, start_pos, &  Len(as_oldstr), as_newstr) // Find the next occurrence of old_str. start_pos = Pos(as_src, as_oldstr, &  start_pos+Len(as_newstr)) Loop

end subroutine

public function integer of_setrequestor (datawindow adw_requestor);If IsNull(adw_requestor) Or Not IsValid(adw_requestor) Then Return -1End If

idw_Requestor = adw_requestor

toolTip.addtool(adw_requestor,“”,0)Return 1

end function

on n_cst_dwsrv_autohint.createcall super::createTriggerEvent( this, “constructor” )end on

on n_cst_dwsrv_autohint.destroyTriggerEvent( this, “destructor” )call super::destroyend on

5、uo_dw_query

forwardglobal type uo_dw_query from datawindowend typeend forward

global type uo_dw_query from datawindowinteger width = 1797integer height = 712integer taborder = 1boolean hscrollbar = trueboolean vscrollbar = trueboolean livescroll = trueborderstyle. borderstyle. = stylelowered!event mousemove pbm_mousemoveevent ue_mouseup pbm_lbuttonupevent ue_lbuttondown pbm_lbuttondownevent ue_mousemove pbm_mousemoveend typeglobal uo_dw_query uo_dw_query

type prototypesFunction ulong SetCapture(ulong hWnd) Library “USER32.DLL”Function BOOLEAN ReleaseCapture() Library “USER32.DLL”FUNCTION ulong GetCapture() LIBRARY “user32.dll”

end prototypes

type variablesPublic: Boolean SortAfterClickOnHeader = True Boolean AutoHint = FalsePrivate: n_cst_dwsrv_gridSort inv_gridSort n_cst_dwsrv_autoHint inv_antohintend variables

event ue_mouseup;If SortAfterClickOnHeader And IsValid(inv_gridSort) Then inv_gridSort.Event ue_lbuttonup(flags,xpos,ypos)End If

end event

event ue_lbuttondown;If SortAfterClickOnHeader And IsValid(inv_gridSort) Then inv_gridSort.Event ue_lbuttondown(flags,xpos,ypos)End If

end event

event ue_mousemove;If AutoHint And IsValid(inv_antohint) Then inv_antohint.Event ue_MouseMove(flags,xpos,ypos)End Ifend event

on uo_dw_query.createend on

on uo_dw_query.destroyend on

event constructor;SetTransObject(sqlca)

If SortAfterClickOnHeader Then inv_gridSort = Create n_cst_dwsrv_gridSort inv_gridSort.of_SetRequestor(This)End IfIf AutoHint Then inv_antohint = Create n_cst_dwsrv_autoHint inv_antohint.of_SetRequestor(This)End If

end event

event rowfocuschanged;//

end event

event clicked;if row0 then this.setRow(row)end ifend event

event dberror;if SQLDBCode = -1 then int li_rtn //重新连接成功,则返回 li_rtn = SetTranSobject(sqlca) if li_rtn = 1 then return 1end if

//display different message according the datawindow is freeform. or notIf This.Object.datawindow.processing = “0” Then gf_dberrormsg(SQLDBCode,SQLErrText,row , “freeform”)Else gf_dberrormsg(SQLDBCode , SQLErrText , row , “”)End Ifsqlca.SQLCode = -1Return 1

end event

event destructor;If IsValid(inv_gridSort) Then Destroy inv_gridSortEnd If

If IsValid(inv_antohint) Then Destroy inv_antohintEnd If

end event

event itemerror;string ls_column , ls_message

if trim(data) = “” then return 3 end ifls_column = dwo.namels_message = this.describe(ls_column + “.validationmsg”)if trim(ls_message) “?” then messagebox(“提示信息” , ls_message)  return 3else messagebox(“提示信息” , “该项数据不合法!”) return 3end if

/* 各返回值意义: 0-拒绝此数值,显示错误消息 1-拒绝此数值,但不显示错误消息 2-接受此数值,

3-拒绝此数值,但允许改变焦点,用原值来代替新值*/end event

篇5:用SQL进行单表查询数据库教程

单表查询是相对多表查询而言的,指从一个数据表中查询数据,

用SQL进行单表查询数据库教程

4.2.1 查询所有的记录

在【命令编辑区】执行输入“select * from scott.emp”,然后单击【执行】按钮,出现如图4.3所示的emp数据表所有记录。

【参见光盘文件】:\第4章\4.2\421.sql。

select * from 数据表,这里的“*”代表数据表中所有的字段。

4.2.2 查询所有记录的某些字段

在【命令编辑区】输入“select empno,ename,job from scott.emp”,然后单击【执行】按钮,将显示emp数据表的empno、ename和job字段,如图4.4所示。

【参见光盘文件】:\第4章\4.2\422.sql。

select 字段名1, 字段名2,…… from 数据表,将显示某些特定的字段,注意这里的字段名之间的逗号是英文状态下的逗号。

4.2.3 查询某些字段不同记录

在图4.4所示的job字段中,可以发现有相同的数据,为了查询有多少种不同的job,在【命令编辑区】输入“select distinct job from scott.emp”,然后单击【执行】按钮,出现如图4.5所示的结果。

【参见光盘文件】:\第4章\4.2\423.sql。

select distinct 字段名 from 数据表,这里的“distinct”保留字指在显示时去除相同的记录,与之对应的是“all”将保留相同的记录,默认为“all”。

4.2.4 单条件的查询

(1)在【命令编辑区】输入“select empno,ename,job from scott.emp where job=’MANAGER’”,然后单击【执行】按钮,出现如图4.6所示的字符型字段条件查询的结果,查询的是job为MANAGER的记录。

【参见光盘文件】:\第4章\4.2\424-1.sql。

(2)在【命令编辑区】输入“select empno,ename,sal from scott.emp where sal<=2500”,然后单击【执行】按钮,出现如图4.7所示的数字型字段条件查询的结果,查询的是满足sal小于等于2500的记录。

【参见光盘文件】:\第4章\4.2\424-2.sql。

where可以指定查询条件,如果是指定字符型字段查询条件,形式为字段名 运算符 '字符串';如果是指定数字型字段查询条件,形式为字段名 运算符 '字符串'。 单条件查询使用的比较运算符如表4.1所示。

【参见光盘文件】:\第4章\4.2\table41.sql。

表4.1 比较运算符名称实例=(等于)select * from scott.emp where job=’MANAGER’;select * from scott.emp where sal=1100;!= (不等于)select * from scott.emp where job!=’MANAGER’;select * from scott.emp where sal!=1100;^=(不等于)select * from scott.emp where job^=’MANAGER’;select * from scott.emp where sal^=1100;(不等于)select * from scott.emp where job’MANAGER’;select * from scott.emp where sal1100;<(小于)select * from scott.emp where sal<2000;select * from scott.emp where job<’MANAGER’;>(大于)select * from scott.emp where sal>2000;select * from scott.emp where job>’MANAGER’;<=(小于等于)select * from scott.emp where sal<=2000;select * from scott.emp where job<=’MANAGER’;>=(大于等于)select * from scott.emp where sal>=2000;select * from scott.emp where job>=’MANAGER’;in(列表)select * from scott.emp where sal in (2000,1000,3000);select * from scott.emp where job in (’MANAGER’,’CLERK’);not in(不在列表)select * from scott.emp where sal not in (2000,1000,3000);select * from scott.emp where job not in (’MANAGER’,’CLERK’);between(介于之间)select * from scott.emp where sal between 2000 and 3000;select * from scott.emp where job between ’MANAGER’ and ’CLERK’;not between (不介于之间)select * from scott.emp where sal not between 2000 and 3000;select * from scott.emp where job not between ’MANAGER’ and ’CLERK’;like(模式匹配)select * from scott.emp where job like ’M%’;select * from scott.emp where job like ’M__’;not like (模式不匹配)select * from scott.emp where job not like ’M%’;select * from scott.emp where job not like ’M__’;Is null (是否为空)select * from scott.emp where sal is null;select * from scott.emp where job is null;is not null(是否为空)select * from scott.emp where sal is not null;select * from scott.emp where job is not null;

like和not like适合字符型字段的查询,%代表任意长度的字符串,_下划线代表一个任意的字符,

like ‘m%’ 代表m开头的任意长度的字符串,like ‘m__’ 代表m开头的长度为3的字符串。

4.2.5 组合条件的查询

(1)在【命令编辑区】输入“select empno,ename,job from scott.emp where job>=’CLERK’ and sal<=2000”,然后单击【执行】按钮,出现如图4.8所示的逻辑与组合查询的结果。

【参见光盘文件】:\第4章\4.2\425-1.sql。

(2)在【命令编辑区】输入“select empno,ename,job from scott.emp where job>=’CLERK’ or sal<=2000”,然后单击【执行】按钮,出现如图4.9所示的逻辑或组合查询的结果。

【参见光盘文件】:\第4章\4.2\425-2.sql。

(3)在【命令编辑区】输入“select empno,ename,job from scott.emp where not job=’CLERK’”,然后单击【执行】按钮,出现如图4.10所示的逻辑非组合查询的结果。

【参见光盘文件】:\第4章\4.2\425-3.sql。

“not job=’CLERK’”等价于“job’CLERK’”。

组合条件中使用的逻辑比较符如表4.2所示。

【参见光盘文件】:\第4章\4.2\table42.sql。

表4.2 逻辑比较符

名称实例and(与)select * from scott.emp where job=’MANAGER’ and sal2000;or (或)select * from scott.emp where job!=’MANAGER’ or sal2000;not(非)select * from scott.emp where not job>=’MANAGER’;

4.2.6 排序查询

在【命令编辑区】输入“select empno,ename,job from scott.emp where job<=’CLERK’ order by job asc,sal desc”,然后单击【执行】按钮,出现如图4.11所示的排序查询的结果。

【参见光盘文件】:\第4章\4.2\426.sql。

order by 可以指定查询结果如何排序,形式为字段名 排序关键词;asc代表升序排列,desc代表降序排列,多个排序字段之间通过逗号分割。若有where查询条件,order by要放在where语句后面。

4.2.7 分组查询

分组查询是指将查询结果按照字段分组。

(1)在【命令编辑区】输入“select empno,ename,job,sal from scott.emp group by job,empno,ename,sal having sal<=2000”,然后单击【执行】按钮,出现如图4.12所示的分组查询的结果。

【参见光盘文件】:\第4章\4.2\427-1.sql。

(2)在【命令编辑区】输入“select empno,ename,job,sal from scott.emp where sal<=2000 group by job,empno,ename,sal”,然后单击【执行】按钮,出现如图4.13所示的分组查询的结果。

【参见光盘文件】:\第4章\4.2\427-2.sql。

where检查每条记录是否符合条件,having是检查分组后的各组是否满足条件。having语句只能配合group by语句使用,没有group by时不能使用having,但可以使用where。

4.2.8 字段运算查询

可以利用几种基本的算术运算符来查询数据。

常见的+(加)、-(减)、*(乘)、/(除)4种算术运算都可以用来查询数据。

在【命令编辑区】输入“select empno,ename,sal,mgr,sal+mgr from scott.emp”,然后单击【执行】按钮,出现如图4.14所示的结果。

【参见光盘文件】:\第4章\4.2\428.sql。

利用算术运算符仅仅适合多个数值型字段或字段与数字之间的运算。

4.2.9 变换查询显示

在【命令编辑区】输入“select empno 编号,ename 姓名,job 工作,sal 薪水 from scott.emp”,然后单击【执行】按钮,出现如图4.15所示的结果,可以将默认的字段名以设定的名称显示。

【参见光盘文件】:\第4章\4.2\429.sql。

以上我们学习了对单个数据表的查询语句。将上面这些基本的实例经过组合,就可以完成基本的日常数据查询任务,接下来进一步学习多表查询。

索引对查询条件顺序的影响数据库教程

关系型数据库基础之:简单的数据查询

用Excel做数据分析―描述统计EXCEL基本教程

用Excel做数据分析―直方图EXCEL基本教程

什么是数据仓库数据库教程

自定义链接后端数据库数据库教程

Building a TSQL Loop数据库教程

用函数简化你的字符串连接语句数据库教程

怎样去宣传数据仓库?数据库教程

oracle里的常用命令数据库教程

《用ADO对Excel的数据查询数据库教程(共5篇).doc》
将本文的Word文档下载到电脑,方便收藏和打印
推荐度:
点击下载文档

文档为doc格式

点击下载本文文档