分享你我的心得.
共乘一片美好网络.

ASP调用存储过程

MS SQL存储过程
Create proc sp_join
@result int output,
@email nvarchar(30),
@username nvarchar(15)
AS

— 开始事务
Begin Tran
INSERT INTO users(username, email) VALUES(@username, @email)
IF @@ERROR <> 0 GOTO back

INSERT INTO register(username) VALUES(@userName)
IF @@ERROR <> 0 GOTO back

— 提交事务
Set @result = 1
Commit Tran
Return

— 回滚事务
back:
Set @result = 0
RollBack Tran
Return

数据库连接代码
Sub Command(oCmd)
Set oCmd = Server.CreateObject("ADODB.Command")
End Sub

Sub Connection(oConn)
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "Provider=SQLOLEDB;Server=;User ID=;Password=;Database=;"
End Sub

Sub Destroy(obj)
If isObject(obj) Then Set obj = Nothing
End Sub

ASP调用代码
Dim strEmail, strUserName
Dim objCmd, objConn, intResult

strEmail = Request.Form("email")
strUserName = Request.Form("username")

‘服务器端数据验证(略)

Command objCmd
Connection objConn

With objCmd
.ActiveConnection = objConn
.CommandType = 4
.CommandText = "sp_join"
.Parameters.Refresh
.Parameters("@email") = strEmail
.Parameters("@username") = strUserName
.Execute
End With
intResult = objCmd.parameters("@result")

Destroy objCmd
Destroy objConn

If intResult = 0 Then
Response.Write("注册失败")
Else
Response.Write("注册成功")
End If
 

这是一个简单的例子,希望能起到抛砖引玉的作用。

赞(0)
未经允许不得转载:小叶白龙博客 » ASP调用存储过程
分享到: 更多 (0)

评论 37

评论前必须登录!