The database operations class for VBS,

Source: Internet
Author: User
Tags count error handling
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>





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.