在ASP页面进行参数化查新一例

例子很明了,一看就明白。代码如下:

VBScript 代码
< %
' ************ 定义常量 *******************
'
---- ParameterDirectionEnum Values ----
Const adParamUnknown = & H0000
Const adParamInput = & H0001
Const adParamOutput = & H0002
Const adParamInputOutput = & H0003
Const adParamReturnValue = & H0004

' ---- CommandTypeEnum Values ----
Const adCmdUnknown = & H0008
Const adCmdText = & H0001
Const adCmdTable = & H0002
Const adCmdStoredProc = & H0004
Const adCmdFile = & H0100
Const adCmdTableDirect = & H0200

' ---- DataTypeEnum Values ----
Const adEmpty = 0
Const adTinyInt = 16
Const adSmallInt = 2
Const adInteger = 3
Const adBigInt = 20
Const adUnsignedTinyInt = 17
Const adUnsignedSmallInt = 18
Const adUnsignedInt = 19
Const adUnsignedBigInt = 21
Const adSingle = 4
Const adDouble = 5
Const adCurrency = 6
Const adDecimal = 14
Const adNumeric = 131
Const adBoolean = 11
Const adError = 10
Const adUserDefined = 132
Const adVariant = 12
Const adIDispatch = 9
Const adIUnknown = 13
Const adGUID = 72
Const adDate = 7
Const adDBDate = 133
Const adDBTime = 134
Const adDBTimeStamp = 135
Const adBSTR = 8
Const adChar = 129
Const adVarChar = 200
Const adLongVarChar = 201
Const adWChar = 130
Const adVarWChar = 202
Const adLongVarWChar = 203
Const adBinary = 128
Const adVarBinary = 204
Const adLongVarBinary = 205
Const adChapter = 136
Const adFileTime = 64
Const adPropVariant = 138
Const adVarNumeric = 139
Const adArray = & H2000

Dim rs, cmd, cn
Set cmd = Server.CreateObject( " ADODB.Command " )
Set cn = Server.CreateObject( " ADODB.Connection " )
' 此处连接的是SQL Server 2008数据库,其他数据库修改连接字符串。
cn.Open " Provider=SQLNCLI10;Server=(local);Database=数据库名称;Uid=数据库登录名;Pwd=密码; "
With cmd
    .ActiveConnection
= cn
    .CommandType
= adCmdText
    .CommandText
= " Select * From BaseObject Where parentname LIKE ? And contentclass=? "
    .Prepared
= True
    .Parameters.Append .CreateParameter(
" parentname " ,adVarChar,adParamInput, 512 , " %/ItemImage/% " )
    .Parameters.Append .CreateParameter(
" mengxianhui " ,adVarChar,adParamInput, 512 , " urn:schemas-mengxianhui-com-cn:basedocument " )
    
Set rs = .Execute
End With
While Not rs.EOF
  Response.Write
" <li> " & rs( " displayname " )
  rs.MoveNext
Wend
Set cmd = Nothing
Set rs = Nothing
Set cn = Nothing
%
>

 也可以写出下面的格式:

VBScript 代码
Dim rs, cmd, cn
Set cmd = Server.CreateObject( " ADODB.Command " )
Set cn = Server.CreateObject( " ADODB.Connection " )
' 此处连接的是SQL Server 2008数据库,其他数据库修改连接字符串。
cn.Open " Provider=SQLNCLI10;Server=(local);Database=数据库名称;Uid=数据库登录名;Pwd=密码; "
With cmd
    .ActiveConnection
= cn
    .CommandType
= adCmdText
    .CommandText
= " Select * From BaseObject Where parentname LIKE ? And contentclass=? "
    .Prepared
= True
    .Parameters(
0 ).Value = " %/ItemImage/% "
    .Parameters(
1 ).Value = " urn:schemas- mengxianhui -com-cn:basedocument "
    
Set rs = .Execute
End With
While Not rs.EOF
  Response.Write
" <li> " & rs( " displayname " )
  rs.MoveNext
Wend
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值