Data | Database <!--
Frog Frogs recommended: VBS database Operations class, this class implements the usual major database operations, because we are dealing with the database every day, sometimes it is convenient to use such a class, but do not know how practical, because in the performance and error handling has not done a lot of consideration, so do not know how its versatility.
It is even more perfect if someone can add dynamic error handling to the class or optimize performance. PS: This class is also to practice the use of the VBS class.
-->
<%
Class Classado
Private Conn_c
Private Rs_c
Public strconn
Private Sub Class_Initialize ' defines initialization events for classes
End Sub
Private Sub class_terminate ' sets Terminate event. ' Define the purge event for the class
Rs_c.close
Set rs_c=nothing
Conn_c.close
Set conn_c=nothing
End Sub
Public Function opendb () Open database
If IsEmpty (strconn) Then
Response. Write ("No database connection string Set")
Response.End
End If
If IsEmpty (Conn_c) Then
Set conn_c=server.createobject ("ADODB. Connection ")
Conn_c.open strconn
Else
Response. Write ("Database is already open")
Response.End
End If
End Function
Public Function getrs (ByVal strSQL) ' Get recordset
If IsEmpty (Conn_c) Then
OPENDB ()
End If
Set rs_c=server.createobject ("ADODB. RecordSet ")
Rs_c.open strsql,conn_c,1,1
Set Getrs=rs_c
End Function
Public Function Exesql (ByVal strSQL) ' executes an SQL statement for inserting, updating, deleting records
If IsEmpty (Conn_c) Then
OPENDB ()
End If
Conn_c.execute (strSQL)
End Function
End Class
%>
<%
' On Error Resume Next ' When debugging the program, please remove this sentence
strconn= "Driver={sql Server};server=192.168.0.110;database=northwind;uid=sa;pwd=sa;"
Set C=new Classado
C.strconn=strconn
C.OPENDB ()
Strsql= "SELECT Employeeid,titleofcourtesy +" + LastName + "+ FirstName as FullName from Employees"
Arr_wawa=c.getrs (strSQL). GetRows ()
Set Rs=c.getrs (strSQL)
%>
<table width= "100%" border= "0" cellspacing= "1" >
<%
If not rs.eof Then
For I=0 to Rs.fields.count-1
Response.Write Rs.fields (i) .name& ""
Next
Response.Write "<br>"
Do as not rs.eof
For I=0 to Rs.fields.count-1
Response.Write Rs.fields (i) .value& ""
Next
Response.Write "<br>"
Rs.movenext
Loop
End If
%>
<table width= "100%" border= "0" cellspacing= "1" >
<% If not IsEmpty (Arr_wawa) Then%>
<% for I=0 to UBound (arr_wawa,2)%>
<tr>
<% for J=0 to UBound (arr_wawa,1)%>
<td><%= Arr_wawa (j,i)%></td>
<% Next%>
</tr>
<% Next%>
<% Else%>
<tr>
<td> No Records </td>
</tr>
<% End If%>
</table>