当前位置: 网学 > 编程文档 > ASP > 正文

在线管理数据库 类

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 13/06/17

以下是网学网为您推荐的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()

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号