一个连接数据库的Class类

连接数据库

Option Explicit

'local variable(s) to hold property value(s)
Private lsServer As String 'local copy
Private lsDatabase As String
'local variable(s) to hold property value(s)
Private lsUserName As String 'local copy
Private lsPassword As String 'local copy
Private lsSelectSQL As String 'local copy
'local variable(s) to hold property value(s)
Private lsTable As String 'local copy

Public Property Let Table(ByVal vData As String)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.Table = 5
lsTable = vData
End Property

Public Property Get Table() As String
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.Table
Table = lsTable
End Property

Public Property Let SelectSQL(ByVal vData As String)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.SelectSQL = 5
lsSelectSQL = vData
End Property

Public Property Get SelectSQL() As String
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.SelectSQL
SelectSQL = lsSelectSQL
End Property

Public Property Let Password(ByVal vData As String)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.Password = 5
lsPassword = vData
End Property

Public Property Get Password() As String
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.Password
Password = lsPassword
End Property

Public Property Let UserName(ByVal vData As String)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.UserName = 5
lsUserName = vData
End Property

Public Property Get UserName() As String
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.UserName
UserName = lsUserName
End Property

Public Property Let Server(ByVal vData As String)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.Server = 5
lsServer = vData
End Property

Public Property Get Server() As String
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.Server
Server = lsServer
End Property

Public Property Let Database(ByVal vData As String)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.Database = 5
lsDatabase = vData
End Property

Public Property Get Database() As String
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.Database
Database = lsDatabase
End Property

Public Function ConnectDatabaseByODBCDNS(lsDNS As String) As ADODB.Connection
On Error GoTo Errhandle
Dim Conn As New ADODB.Connection
Dim strConn As String
strConn = "DSN=" & lsDNS & _
";UID=" & lsUserName & _
";Pwd=" & lsPassword
If Conn.State = adStateOpen Then
Conn.Close
End If
Conn.Open strConn
Conn.CursorLocation = adUseClient
Set ConnectDatabaseByODBCDNS = Conn
Exit Function
Errhandle:
Err.Raise 102, "DBConn.Cls", "Can't Connect To The " & Database & " Database!"
End Function
Public Function ConnectDatabaseByODBC() As ADODB.Connection
On Error GoTo Errhandle
Dim Conn As New ADODB.Connection
Dim strConn As String
strConn = "Provider=MSDASQL.1" & _
";User ID=" & lsUserName & _
";Password=" & lsPassword & _
";Persist Security Info=False" & _
";Initial Catalog=" & lsDatabase & _
";Data Source=" & lsServer
If Conn.State = adStateOpen Then
Conn.Close
End If
Conn.Open strConn
Conn.CursorLocation = adUseClient
Set ConnectDatabaseByODBC = Conn
Exit Function
Errhandle:
Err.Raise 10

时间: 2024-09-09 15:58:19

一个连接数据库的Class类的相关文章

java-为什么不可能创建一个继承OnTouchListener的类?

问题描述 为什么不可能创建一个继承OnTouchListener的类? Android SDK在TouchEvent有一个接口(android.view.View.OnTouchListener).我不知道为什么下面这一行是错误的.Eclipse在OnTouchListener报错. public class TouchHandler extends OnTouchListener{ 如果我改为public interface TouchHandler extends OnTouchListen

封装的一个asp.net验证码类

第一个反映是验证码的这些属性是否可以设置(也就是说是封装成一个类,然后以暴露公有属性和方法的方式来使用的,还是在直接在一般处理程序中实现了验证码的生成到输出),结果比较可惜,是后者...... 里面的算法感觉挺不错,至少对于我这种对算法几乎是不懂的人来说是这样,于是想到去封装一下她然后无耻地纳入自己的类库中去^^ old原文件如下:点击下载 首先分析一下这份代码中的不足(自己觉得的): 1.面向过程式的编程,如果要修改验证码的属性,例如修改字体的大小.背景颜色等细节的东西,需要去一般处理程序中找

一个PHP MySQL操作类...

<?php /** * MySQL 数据库操作工具类, 方便数据库操作. * 示例见底部注释. * @author: http://www.ideawu.net/blog/ */ class Mysql{ var $conn; var $query_list = array(); public $query_count = 0; public function __construct($c){ if(!isset($c['port'])){ $c['port'] = '3306'; } $ser

给网站添加一个注册表 之 “类的应用”

注册表 下面,我们用这个"注册表"类来写一个简单的"计数器"应用,代码如下: pagecount.asp: <!-- #Include File="registry_class_inc.asp" --><%Dim RegSet Reg = New RegistryObjectReg.Path = Server.MapPath("pagecount.xml") Const BaseCount = 8000 '计

ASP编写完整的一个IP所在地搜索类

ASP编写完整的一个IP所在地搜索类的修正文稿 修正了查询方法,查询的方法和追捕的一致:只是追捕会自动更正IP. 还有个函数的书写错误,也已经修正: 包括增加了一个IP地址正确性的验证函数.(只是从格式上判断) <% Server.ScriptTimeout = &HE10 '&H3C Response.Buffer = ("S.F." = "S.F.") Dim IpSearch '建立对象 Set IpSearch = New clsIpS

一个CFileFind的扩展类CFileFindExt

一.类CfileFindExt功能说明 大家经常需要对指定目录下的所有文件进行搜索或其它相同操作.若文件数很多,逐一对每个文件手工操作,很费时.本文提供一个搜索或处理指定目录下的所有文件的C++类.作者用基于层次遍历的非递归算法(以减少运行时的时间和空间开销)实现了一个 CFileFind 的扩展类 CFileFindExt,该类可以对指定目录下的所有文件进行搜索或相同的处理操作. 二.类 CFileFindExt 的接口说明及用法示例: 1.头文件.处理函数.以及类的声明: #include

介绍一个增强的数据库类CDataSet

因为MFC完全支持数据库应用程序的开发,所以大多数数据库应用都使用CDatabase和CRecordset类,并且类向导(Class Wizard)提供了快速简易的方式来使用这两个类.有一点不足的就是当应用程序涉及到多表数据库时,类向导将产生大量的关于记录集的源码文件使得工程给人的感觉很臃肿混乱. 本文介绍如何使用一个模板记录集类来降低类向导所产生的记录集文件的数量,同时增强记录集类(CRecordset)的功能.这个模板记录集类叫做:CDataSet.它的主要目的是降低代码量,为数据对象数组提

一个UBB的PHP类

/*Text Encode ClassWrite by q3boy 2003.3.10usage:$eq = new EncodeQ3boy($str);初始化类//以下为ubbEncode参数$eq->url = true; //启用url自动解析 默认false$eq->html = true; //启用HTML编码(处理<,>,全角/半角空格,制表符,换行符)默认true$eq->image = true; //启用图象标签解析 默认true$eq->font =

探讨C++实现一个不可被继承的类

C#和Java都提供了一种机制让一个类不能被继承,如C#中的sealed关键字和Java的final关键字,然而C++程序员就没这么好命了.不过C++也可以模拟出这种效果,原理基于:子类的构造函数会自动调用父类的构造函数,同理析构函数也是一样.如果父类的构造函数和析构函数被设为私有的话,那么子类就无法调用,也就达到了父类不可被继承的目的了.原理很简单,按此原理我也实作出一个自认为很实用的工具类,在此献下丑,欢迎大家批评: template< typename TDerive, typename