ACTIVE SERVER PAGE > Command - Parameter
등록일 : 2017-07-04 17:06
조회수 : 92,931
Parameters 컬렉션은 Command 개체의 Parameter 개체들을 포함하고 있는 컬렉션입니다.
Parameters 컬렉션은 저장프로시져 또는 질의에 대한 매개변수를 전달할때 주로 사용되는 개체입니다.
Parameters 개체는 append 메서드를 사용해서 Parameters 컬렉션에 추가됩니다.
매개변수를 전달하는 방법에는 Command 개체의 Parameters 컬렉션을 사용하는 방법과 Excute 메서드의
두번째 인수로 배열값을 지정해서 매개변수를 넘겨주는 방법이 있습니다.
간단한 프로시져를 보면,,,,
CREATE proc main_news_list2
@category1_code varchar(20),
@category2_count int OUTPUT
as
begin
select @category2_count = count(category2_code) from category2 where category1_code = @category1_code
end
카운터를 가지고 오는 예제인데요. asp 프로그래밍을 보겠습니다.
<!--METADATA TYPE="typelib" NAME="ADODB Type Library" File="C:\Program Files\Common Files System\ado\msado15.dll" -->
strName = "2"
Dim objCon
Dim strConnection
Set objCnn = Server.CreateObject("ADODB.Connection")
strConnect="Provider=sqloledb;Data Source=xxx.xxx.xxx.xxx;Initial Catalog=xxx;User ID=sa;Password=xx;"
objCnn.Open strConnect
Dim objCmd
Set objCmd = Server.CreateObject("ADODB.Command")
with objCmd
ActiveConnection = objCnn
.CommandText = "main_news_list2"
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter("@category1_code",advarchar,adParamInput,20)
.Parameters.Append .CreateParameter("@category2_count",adInteger,adParamOutput,0)
.Parameters("@category1_code") = strName
.Execute , , adExecuteNoRecords
CNT = .Parameters("@category2_count")
End with
%>
레코드 갯수 : <%=CNT%>
위의 예제는 category1_code 값을 넘겨서 count 를 가지고 오는 예제 입니다.
strName 값을 입력해서 @category2_count 값을 가지고 옵니다.