ASP中访问数据库的SQL语句中如何用变量?

wzh 2000-06-15 04:50:00
如题!
...全文
166 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
XiangDong 2000-06-15
  • 打赏
  • 举报
回复
给个例子吧:
dim ParaCarID
dim ParaPwd
dim cmd
set cmd = server.CreateObject ("adodb.command")
set cmd.ActiveConnection = Application("CN")
cmd.CommandText = "procCheckCar"
cmd.CommandType = 4
cmd("@CarID") = trim(Request.Form("txtCarID"))
cmd.Parameters("@CarPwd").Size = 8
cmd("@CarPwd") = trim(Request.Form("txtPwd"))

cmd.Execute
if cmd(0) = 0 then
蝈蝈俊 2000-06-15
  • 打赏
  • 举报
回复
Open (ADO)
Opens a cursor (read-only by default).

Syntax
recordset.Open Source, ActiveConnection, CursorType, LockType, Options

The parts of the Open statement syntax are described in the following table.

Part Description
Source Required. A Variant that evaluates to a table name or a SQL statement (see below).
ActiveConnection Optional. A Variant that evaluates to a String containing a definition for a connection. If supplied, it can only be "" since this property has no meaning on CE.
CursorType



adOpenForwardOnly 0




adOpenDynamic 2
Optional. Default adOpenForwardOnly. Supports the following two values. All other values should generate a run-time error.
Forward-only cursor. Identical to a static cursor except that you can only scroll forward through records. This improves performance in situations when you only need to make a single pass through a recordset. (Default.)

Dynamic cursor. Additions, changes, and deletions by other users are visible, and all types of movement through the recordset are allowed, except for bookmarks if the provider doesn't support them. It is extremely important that the default behavior be forward-only, read-only. Note that the forward-only portion maps well to pegdb_autoincrement.

LockType Optional. A LockTypeEnum value that determines what type of locking (concurrency) the provider should use when opening the Recordset. Can be one of the following constants: adLockReadOnly (1), adLockPessimistic (2), adLockOptimistic (3) or adLockBatchOptimistic. However only adLockReadOnly and adLockOptimistic will be honoured, and all other requests will result in a cursor type of adLockOptimistic.
Options Optional. A CommandTypeEnum value that indicates how the provider should evaluate the Source argument.


Sets or returns one of the following CommandTypeEnum values:

Constant Value Description
adCmdText 1 Evaluates Source as a textual definition of a command (i.e. SQL statement)
adCmdTable 2 Evaluates Source as a table name.
adCmdUnknown 8 The type of command in the Source property is not known. (Default.)


Remarks
Use the Options parameter to optimize evaluation of the Source property. If the Options property value equals adCmdUnknown (8), you may experience diminished performance because ADO must determine if the Source property by attempting to open as a table, stored procedure or as an SQL statement (in that order). If you know what type of command you're using, setting the Options property instructs ADO to go directly to the relevant code. If the Options property does not match the type of command in the Source property, an error occurs when you call the Open method.

When the Open method is called with a non-row returning SQL command (e.g. CREATE TABLE), no recordset is returned and the state of the recordset is closed.

The adLockReadOnly will have to be coded into ADO as PegDB doesn't support the concept of opening a table read-only.


28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧