在Access里使用查询建立存储过程/视图 并使用ASP执行
摘要: 本文演示了 使用 Access查询 构造类似于 MSSQL 存储过程的功能, 并在 ASP 中操作插入数据,显示数据功能.
目录:
1. 在 Access 查询里建表, 名 tt
2. 在 Access 查询里新建查询, 内容为:...
3. 在 ASP 里使用 tt_insertParm 添加10条记录到 表tt
3.1 构造ASP ado 连接函数, fCreateCnn 与 fCloseCnn
3.2 组合使用 fCreateCnn, fCloseCnn, tt_insertParm 添加记录
4. 在 Access 查询里 创建 显示数据用的 存储过程/视图, 内容:...
5. 在 ASP 里使用 tt_selectParm 选取数据
6. 完.
1. 在 Access 查询里建表, 名 tt
输入以下内容到查询, 并执行, 执行后就新建表 tt 了.
说明:
id 字段为自动编号, 并且为主键
title 为文本类型, 长度 255
content 为备注类型
dateandtime 为日期类型
2. 在 Access 查询里新建查询, 内容为:
保存名为: tt_insertParm
作用为: 添加记录到 Access 的存储过程
注: spContent 字段里, 某某无法使用 memo 数据类型.
3. 在 ASP 里使用 tt_insertParm 添加10条记录到 表tt
3.1 构造ASP ado 连接函数, fCreateCnn 与 fCloseCnn
3.2 组合使用 fCreateCnn, fCloseCnn, tt_insertParm 添加记录
4. 在 Access 查询里 创建 显示数据用的 存储过程/视图, 内容:
保存名为: tt_selectParm
说明: 如果 qId 参数值为空, 则选取所有数据, 否则选取 qId 对应的行
5. 在 ASP 里使用 tt_selectParm 选取数据
6. 完.
附注: 还有 更新,删除数据 的 存储过程/视图 没有演示, 不过相信你如果看了以上操作, 这个应该不是问题了
http://www.wzsky.net/html/Program/DataBase/97672.html
目录:
1. 在 Access 查询里建表, 名 tt
2. 在 Access 查询里新建查询, 内容为:...
3. 在 ASP 里使用 tt_insertParm 添加10条记录到 表tt
3.1 构造ASP ado 连接函数, fCreateCnn 与 fCloseCnn
3.2 组合使用 fCreateCnn, fCloseCnn, tt_insertParm 添加记录
4. 在 Access 查询里 创建 显示数据用的 存储过程/视图, 内容:...
5. 在 ASP 里使用 tt_selectParm 选取数据
6. 完.
1. 在 Access 查询里建表, 名 tt
输入以下内容到查询, 并执行, 执行后就新建表 tt 了.
+展开
-SQL
create table tt
(
id autoIncrement
primary key,
title varchar(255),
content memo,
dateandtime date
)
(
id autoIncrement
primary key,
title varchar(255),
content memo,
dateandtime date
)
说明:
id 字段为自动编号, 并且为主键
title 为文本类型, 长度 255
content 为备注类型
dateandtime 为日期类型
2. 在 Access 查询里新建查询, 内容为:
+展开
-SQL
parameters spTitle varchar(255),spContent varchar(255);
insert into tt(title, content, dateandtime)
values([spTitle], [spContent], now())
insert into tt(title, content, dateandtime)
values([spTitle], [spContent], now())
保存名为: tt_insertParm
作用为: 添加记录到 Access 的存储过程
注: spContent 字段里, 某某无法使用 memo 数据类型.
3. 在 ASP 里使用 tt_insertParm 添加10条记录到 表tt
3.1 构造ASP ado 连接函数, fCreateCnn 与 fCloseCnn
+展开
-HTML
<%
function fCreateCnn(cnn)
set cnn=createObject("adodb.connection")
end function
function fCloseCnn(cnn)
cnn.close
set cnn=nothing
end function
%>
function fCreateCnn(cnn)
set cnn=createObject("adodb.connection")
end function
function fCloseCnn(cnn)
cnn.close
set cnn=nothing
end function
%>
3.2 组合使用 fCreateCnn, fCloseCnn, tt_insertParm 添加记录
+展开
-HTML
<%
dim title, content
title="insert title"
content="insert content"
dim cnn, rs
dim i
call fCreateCnn(cnn)
cnn.open conn
for i=1 to 10
cnn.execute("exec tt_insertParm "&title&i&","&content&i)
next
call fCloseCnn(cnn)
if err.number=0 then response.Write "数据已添加" else response.Write "发生错误, 数据未添加"
%>
dim title, content
title="insert title"
content="insert content"
dim cnn, rs
dim i
call fCreateCnn(cnn)
cnn.open conn
for i=1 to 10
cnn.execute("exec tt_insertParm "&title&i&","&content&i)
next
call fCloseCnn(cnn)
if err.number=0 then response.Write "数据已添加" else response.Write "发生错误, 数据未添加"
%>
4. 在 Access 查询里 创建 显示数据用的 存储过程/视图, 内容:
+展开
-SQL
PARAMETERS qId Long;
SELECT *
FROM tt
WHERE id=iif(isNull([qId]),id,[qId])
SELECT *
FROM tt
WHERE id=iif(isNull([qId]),id,[qId])
保存名为: tt_selectParm
说明: 如果 qId 参数值为空, 则选取所有数据, 否则选取 qId 对应的行
5. 在 ASP 里使用 tt_selectParm 选取数据
+展开
-HTML
<%
dim qId, fldNum, i
qId = 10
dim cnn, rs
call fCreateCnn(cnn)
cnn.open conn
set rs = cnn.execute("EXEC tt_selectParm " & qId)
'set rs = cnn.execute("EXEC tt_selectParm null")
fldNum=rs.fields.count-1
do until rs.eof
for i=0 to fldNum
response.write rs(i)
response.write " "
next
response.write "<br/>"
rs.movenext
loop
rs.close
set rs=nothing
call fCloseCnn(cnn)
%>
dim qId, fldNum, i
qId = 10
dim cnn, rs
call fCreateCnn(cnn)
cnn.open conn
set rs = cnn.execute("EXEC tt_selectParm " & qId)
'set rs = cnn.execute("EXEC tt_selectParm null")
fldNum=rs.fields.count-1
do until rs.eof
for i=0 to fldNum
response.write rs(i)
response.write " "
next
response.write "<br/>"
rs.movenext
loop
rs.close
set rs=nothing
call fCloseCnn(cnn)
%>
6. 完.
附注: 还有 更新,删除数据 的 存储过程/视图 没有演示, 不过相信你如果看了以上操作, 这个应该不是问题了
http://www.wzsky.net/html/Program/DataBase/97672.html
加支付宝好友偷能量挖...