以下是网学网为您推荐的ASP-在线管理数据库 类,希望本篇文章对您学习有所帮助。
<%
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 & "=" & ValueText & " " & WhereStr)
If Err.Number <> 0 Then
Call ErrMsg("错误提示:" & Err.Description)
Err.Clear()