ASP(VBSCRTP)用ADODB調用SQL預存程序樣本:
Set Cmd = Server.Createobject("ADODB.Command") '建立對象
Cmd.ActiveConnection = Conn '資料庫連結connection對象
Cmd.CommandText = "預存程序名稱" '要調用的預存程序名稱
Cmd.CommandType = 4 '設定command為調用預存程序方式
Cmd.Parameters.Append Cmd.CreateParameter("@Pid",200,1,30) '添加聲明變數
Cmd.Parameters("@Pid") = Pid '設定聲明變數的值
Set Rs = Cmd.Execute '執行返回
CommandType:
CommandType = 1 (Recordsource由命令文本產生,通常使用SQL)
CommandType = 2 (Recordsource由為單個表名)
CommandType = 4 (Recordsource由預存程序產生)
CommandType = 8 (產生Recordsource命令類型未知,通常使用SQL)
CreateParameter("參數名稱",類型,方向,大小)
參數值的類型:
名稱值 整數值 功能
adDBTimeStamp 135 日期時間資料類型
adDecimal 14 十進位整數值
adDouble 5 雙精確度小數值
adError 10 系統錯誤資訊
AdGUID 72 全域性唯一識別字(Globally unique identifier)
adDispath 9 COM/OLE自動對象(Automation Object)
adInteger 3 4位元組有符號整數
adIUnknown 13 COM/OLE對象
adLongVarBinary 205 大型2位元組值
adLongVarChar 201 大型字串值
adLongVarWChar 203 大型未編碼字串
adNumeric 131 十進位整數值
adSingle 4 單精確度浮點小數
adSmallInt 2 2位元組有符號整數
adTinyInt 16 1位元組有符號整數
adUnsignedBigInt 21 8位元組不帶正負號的整數
adUnsignedInt 19 4位元組不帶正負號的整數
adUnsignedSmallInt 18 2位元組不帶正負號的整數
adUnsignedTinyInt 17 1位元組不帶正負號的整數
adUserDefined 132 使用者自訂資料類型
adVariant 12 OLE對象
adVarBinary 204 雙位元組字元變數值
adVarChar 200 字元變數值
advarchar 202 未編碼字串變數值
adWchar 130 未編碼字串
參數值的方向值:
名稱值 整數值 功能
adParamInput 1 允許資料輸入至該參數當中
adParamOutput 2 允許資料輸出至該參數當中
adParamInputOutput 3 允許資料輸入、輸出至該參數當中
adparamReturnValue 4 允許從一子程式中返回資料至該參數當中