Relaxlife.net数据库操作的应用,数据库操作/表操作/表结构操作/索引(Index),主键操作/字段值操作(原版)
<%
Rem =================================================================
Rem = 类:RLManDBCls
Rem = 说明:数据库操作的应用(用在SQL或ACCESS数据库)
Rem = Revision:1.01 Beta
Rem = 作者:熊氏英雄(cexo255)
Rem = Date:2005/05/6 18:38:10
Rem = QQ:30133499
Rem = MySite:Http://www.Relaxlife.net
Rem = 下载:http://www.relaxlife.net/2005/relaxlife/blogview.asp?logID=179
Rem = QQ群:4341998
Rem = 适用:此类能对数据库进行大部份操作。数据库操作/表操作/表结构操作/索引(Index),主键操作/字段值操作
Rem =================================================================
Class RLManDBCls
Private sDBPath, RLConn, sDBType, sServerName, sUserName, sPassword
Public Count
Private Sub Class_Initialize()
sDBType = ""
End Sub
Private Sub Class_Terminate()
If IsObject(RlConn) Then
RlConn.Close
Set RlConn = Nothing
End if
End Sub
Public Property Let DBType(ByVal strVar)
sDBType = strVar
End Property
Public Property Let ServerName(ByVal strVar)
sServerName = strVar
End Property
Public Property Let UserName(ByVal strVar)
sUserName = strVar
End Property
Public Property Let Password(ByVal strVar)
sPassword = strVar
End Property
’设置数据库路径
Public Property Let DBPath(ByVal strVar)
sDBPath = strVar
Select Case sDBType
Case "SQL"
StrServer = sServerName ’数据库服务器名
StrUid = sUserName ’您的登录帐号
StrSaPwd = sPassword ’您的登录密码
StrDbName = sDBPath ’您的数据库名称
sDBPath = "driver={SQL server};server=" & StrServer & ";uid=" & StrUid & ";pwd=" & StrSaPwd & ";database=" & StrDbName
Case "ACCESS",""
sDBPath = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(sDBPath)
End Select
CheckData RLConn,sDbPath
End Property
’检查数据库链接,(变量名,连接字串)
Private Sub CheckData(DataConn,ConnStr)
On Error Resume Next
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open ConnStr
If Err Then
Err.Clear
Set DataConn = Nothing
ErrMsg("数据库连接出错:" & Replace(ConnStr,"\","\\") & ",\n请检查连接字串,确认您输入的数据库信息是否正确。")
Response.End
End If
End Sub
’检查表是否存在
Function CheckTable(TableName)
On Error Resume Next
RLConn.Execute("select * From " & TableName)
If Err.Number <> 0 Then
Err.Clear()
Call ErrMsg("错误提示:" & Err.Description)
CheckTable = False
Else
CheckTable = True
End If
End Function
’错误提示信息(消息)
Private Sub ErrMsg(msg)
Response.Write msg
Response.Flush
End Sub
’---------------------------------------字段值的操作-----------------------------------------------
’修改字段的值
Public Sub upColumn(ByVal TableName, ByVal ColumnName, ByVal ValueText,ByVal WhereStr)
On Error Resume Next
If WhereStr <> "" Then
If InStr(WhereStr,"Where ")<=0 Then
WhereStr = "Where " & WhereStr
End if
Else
WhereStr = ""
End if
RLConn.Execute("update " & TableName & " set " & ColumnName&n