13. 5. 10.

Classic ASP 와 MS-SQL 연동

<OBJECT RUNAT="server" PROGID=ADODB.Connection id="ObjConn"> </OBJECT>
<%
   dim fs,objFile
   dim ObjSql ,WhereSql ,Rs,i,ListArr
   dim Field0,Field1,,Field2,Field3,Field4
   dim Val1, Val12,Url 
   dim intNowPage ,intPageSize ,intBlockPage 

   Set fs = Server.CreateObject("Scripting.FileSystemObject")
   Set objFile = fs.OpenTextFile("c:\DB_file.dat",1)
   ' c:\DB_file.dat 내용
   ' Provider=SQLOLEDB.1;User ID=sa;Password=1111;Initial Catalog=master;Data Source=123.123.123.123,1433
   ObjConn.open objFile.readline
 
   Val1 = Request.QueryString("Val1")
   Val2 = Request.QueryString("Val2")
 
   If Val1<>"" and Val12<>"" Then
      WhereSql = " WHERE " & Val1 & "='" & Val2 & & "'"
      Url = "&Val1=" & Val1 & "&Val2 =" & Val2
   End If
 
   ObjSql = "SELECT * FROM DB_TABLE" & WhereSql 
 
   Set Rs=ObjConn.Execute(ObjSql)
   If Not Rs.Eof Then ListArr = Rs.Getrows ' DB를 ListArr 에 저장
   Rs.Close
   Set Rs=Nothing
 
   intNowPage = Request.QueryString("page")  ' 현제페이지
   intPageSize = 10    ' 페이지크기
   intBlockPage = 10   ' 페이지묶음크기
 
    If Len(intNowPage) = 0 Then      ' 현제페이지값이없을경우
        intNowPage = 1
    End If

    If isArray(ListArr) then               ' 목록이 있을경우 페이지 수
       intTotalCount = Ubound(ListArr,2)+1
       If (intTotalCount Mod intPageSize)=0 Then
          intTotalPage = int(intTotalCount/intPageSize)
       Else
          intTotalPage = int(intTotalCount/intPageSize)+1
       End if
    End if

   If isArray(ListArr) Then   '자료 있다면 변수에 저장
     ' 페이지 나눌경우(없을경우 0 To Ubound(ListArr,2))
      For i=0+(intNowPage*intPageSize-intPageSize) to (intNowPage*intPageSize)-1   
        If i<=Ubound(ListArr,2) then
           Field0 = ListArr(0,i)
           Field1 = ListArr(1,i)
           Field2 = ListArr(2,i)
           Field3 = ListArr(3,i)
           Field4 = ListArr(4,i)
        End If
     Next
 
   ' 페이지 나누기
If isArray(ListArr) Then 
    intTemp = Int((intNowPage - 1) / intBlockPage) * intBlockPage + 1
 
    If intTemp = 1 Then
     Response.Write("◀")
    Else 
     Response.Write("<a href=""?page=" & intTemp - intBlockPage & Url & """>◀</a>")
    End If
 
    intLoop = 1
 
    Do Until intLoop > intBlockPage Or intTemp > intTotalPage
     If intTemp = CInt(intNowPage) Then
      Response.Write("<font size= 3><b>" & intTemp &"</b></font> " )
     Else
      Response.Write("<a href=""?page=" & intTemp &url &""">" & intTemp& "</a> ")
     End If
     intTemp = intTemp + 1
     intLoop = intLoop + 1
    Loop
 
     If intTemp > intTotalPage Then
       Response.Write("▶")
     Else
       Response.Write("<a href=""?page=" & intTemp & Url &  """>▶</a>")
     End If
   End if
%>

댓글 없음:

댓글 쓰기