A simple stored procedure ~

xiaoxiao2021-03-06  101

<%

'Establish an object

Set Oconn = Server.createObject ("AdoDb.Connection")

SET ORS = Server.createObject ("AdoDb.Recordset")

Set Ocmd = Server.createObject ("AdoDb.command")

'Data Connections

StrConn = "driver = {SQL Server}; server = web; uid = sa; pwd = 123; Database = Stefli_GB"

Oconn.open straconn

'Creating a stored procedure

'strpro = "Create Proc selectname (@ID int, @ name varchar out) as select name from userdata where id = @ id"

'Oconn.execute StrPro

'Transfer parameters

Ocmd.commandtext = "selectname"

Ocmd.commandtype = 4

Ocmd.parameters.Append Ocmd.createParameter ("@ ID", 3, 1)

Ocmd.Parameters ("@ id") = request.form ("id")

Ocmd.Parameters.Append Ocmd.createParameter ("@ name", 4, 2)

Ocmd.activeConnection = OCONN

Set ics = OCMD.EXECUTE ()

'Result output

Response.write "" "& ORS (" Name ") &" "

%>

But a little problem is that ("@name", 4, 2) 4, according to the reason should be 200, don't know why 200 is not, 4 lines, I know, please explain it ~

The following is a table structure and operation results:

Database: Stefli_GB

Table: Userdata

Field name type size

ID INT 4 (Identification)

Name Varchar 50

Data:

ID Name

1 Stefli

2 joy

3 haha

4 Test

Procedure:

Create Proc selectname (@ID int, @ name varchar output)

AS

Select name from userdata where id = @ ID

Go

The result is: Stefli

转载请注明原文地址:https://www.9cbs.com/read-125940.html

New Post(0)