3초기억력

classic asp) ADODB.Command 사용하여 Query 하기 본문

플밍_ASP

classic asp) ADODB.Command 사용하여 Query 하기

잠수콩 2021. 3. 25. 10:16
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

1. DB 객체 연결

Set db = Server.CreateObject("ADODB.Connection")
strConnection ="Provider=sqloledb;Data Source=DB서버,포트;Initial Catalog=DB명;User ID=사용자명;Password=비밀번호;"

db.CursorLocation = 3
db.Open strConnection

 

2. DB 프로시저 실행문

Set Cmd = Server.CreateObject("ADODB.Command")

With Cmd
    .ActiveConnection = db
    .CommandText = "프로시저명"
    .CommandType = adCmdStoredProc
    .Parameters.Append .CreateParameter("@idx", adInteger, adParamInput, 4, idx)
    Set rs = .Execute
End With

If Not(rs.eof Or rs.bof) Then
	getrowRs = rs.getRows()
End If
rs.close
Set rs = nothing
Set Cmd = Nothing

If isArray(getrowRs) Then
	For i = 0 To ubound(getrowRs,2)
    	response.write "아이디 : " & getrowRs(1, i) & "<br>"
    	response.write "이름 : " & getrowRs(2, i) & "<br>"
    Next 
End If

 

3. DB RecordSet 실행문

sql = "select * from 회원테이블 where idx = ?"
Set Cmd = Server.CreateObject("ADODB.Command")
With Cmd
  .ActiveConnection = db
  .CommandType = adCmdText
  .CommandText = sql
  .Parameters.Append Cmd.CreateParameter("idx", adInteger, adParamInput, 0, idx)
End With
Set rs = Cmd.Execute()
Set Cmd = Nothing
If Not(rs.eof Or rs.bof) Then
  id = rs("id")
  name = rs("name")
Else
	response.write "조회 안됨"
End If
Call closeRs(rs)
Comments