天枫庄资源网 Design By www.wosibo.com
<%
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()
End If
End Sub
'执行SQL语句
Public Sub Execute(StrSql)
Set RsCount=Server.CreateObject("ADODB.RecordSet")
On Error Resume Next
RsCount = RLConn.Execute(StrSql)
If Left(StrSql,12) = "Select Count" Then Count = RsCount(0)
If Err.Number <> 0 Then
Call ErrMsg("错误提示:" & Err.Description)
Err.Clear()
End If
RsCount.Close
Set RsCount = Nothing
End Sub
'---------------------------------------索引(Index),视图(View),主键操作-----------------------------------------------
'添加字段索引
Public Function AddIndex(ByVal TableName, ByVal IndexName, ByVal ValueText)
On Error Resume Next
RLConn.Execute("CREATE INDEX " & IndexName & " ON [" & TableName & "]([" & ValueText & "])")
If Err.Number <> 0 Then
Call ErrMsg ("在 " & TableName & " 表新建" & IndexName & "索引错误,原因" & Err.Description & "请手工修改该索引。")
Err.Clear()
AddIndex = False
Else
AddIndex = True
End If
End Function
'删除表索引
Public Function DelIndex(ByVal TableName, ByVal IndexName)
On Error Resume Next
RLConn.Execute("drop空格INDEX [" & TableName & "]." & IndexName)
If Err.Number <> 0 Then
Call ErrMsg ("在 " & TableName & " 表删除" & IndexName & "索引错误,原因" & Err.Description & "请手工删除该索引。")
Err.Clear()
DelIndex = False
Else
DelIndex = True
End If
End Function
'更改表TableName的定义把字段ColumnName设为主键
Public Function AddPRIMARYKEY(ByVal TableName, ByVal ColumnName)
On Error Resume Next
TableName = Replace(Replace(TableName,"[",""),"]","")
RLConn.Execute("ALTER TABLE "& TableName & " ADD CONSTRAINT PK_"&TableName&" PRIMARY KEY (" & ColumnName & ")")
If Err.Number <> 0 Then
Call ErrMsg ("在 " & TableName & " 将字段" & ColumnName & " 添加为主键时出错,原因 " & Err.Description & "请手工修改该字段属性。")
Err.Clear()
AddPRIMARYKEY = False
Else
AddPRIMARYKEY = True
End If
End Function
'更改表TableName的定义把字段ColumnName主键的定义删除
Public Function DelPRIMARYKEY(ByVal TableName, ByVal ColumnName)
On Error Resume Next
RLConn.Execute("ALTER TABLE "& TableName & " drop空格PRIMARY KEY (" & ColumnName & ")")
If Err.Number <> 0 Then
Call ErrMsg ("在 " & TableName & " 将字段" & ColumnName & " 主键的定义删除时出错,原因" & Err.Description & "请手工修改该字段属性。")
Err.Clear()
DelPRIMARYKEY = False
Else
DelPRIMARYKEY = True
End If
End Function
'检查主键是否存在,返回该表的主键名
Function GetPrimaryKey(TableName)
on error Resume Next
Dim RsPrimary
GetPrimaryKey = ""
Set RsPrimary = RLConn.OpenSchema(28,Array(Empty,Empty,TableName))
If Not RsPrimary.Eof Then GetPrimaryKey = RsPrimary("COLUMN_NAME")
Set RsPrimary = Nothing
If Err.Number <> 0 Then
Call ErrMsg("数据库不支持检测数据表 " & TableName & " 的主键。原因 :" & Err.Description)
Err.Clear()
End If
End Function
'---------------------------------------表结构操作-----------------------------------------------
'添加新字段
Public Function AddColumn(TableName,ColumnName,ColumnType)
On Error Resume Next
RLConn.Execute("Alter Table [" & TableName & "] Add [" & ColumnName & "] " & ColumnType & "")
If Err Then
ErrMsg ("新建 " & TableName & " 表中字段错误,请手动将数据库中 <B>" & ColumnName & "</B> 字段建立,属性为 <B>"&ColumnType& "</B>,原因" & Err.Description)
Err.Clear
AddColumn = False
Else
AddColumn = True
End If
End Function
'更改字段通用函数
Public Function ModColumn(TableName,ColumnName,ColumnType)
On Error Resume Next
RLConn.Execute("Alter Table [" & TableName & "] Alter Column [" & ColumnName & "] " & ColumnType & "")
If Err Then
Call ErrMsg ("更改 " & TableName & " 表中字段属性错误,请手动将数据库中 <B>" & ColumnName & "</B> 字段更改为 <B>" & ColumnType & "</B> 属性,原因" & Err.Description)
Err.Clear
ModColumn = False
Else
ModColumn = True
End If
End Function
'删除字段通用函数
Public Function DelColumn(TableName,ColumnName)
On Error Resume Next
If sDBType = "SQL" THen
RLConn.Execute("Alter Table [" & TableName & "] drop空格Column [" & ColumnName & "]")
Else
RLConn.Execute("Alter Table [" & TableName & "] drop空格[" & ColumnName & "]")
End if
If Err Then
Call ErrMsg ("删除 " & TableName & " 表中字段错误,请手动将数据库中 <B>" & ColumnName & "</B> 字段删除,原因" & Err.Description)
Err.Clear
DelColumn = False
Else
DelColumn = True
End If
End Function
'---------------------------------------表操作---------------------------------------------------
'打开表名对象
Private Sub ReNameTableConn()
On Error Resume Next
Set objADOXDatabase = Server.CreateObject("ADOX.Catalog")
objADOXDatabase.ActiveConnection = ConnStr
If Err Then
ErrMsg("建立更改表名对象出错,您所要升级的空间不支持此对象,您很可能需要手动更改表名,原因" & Err.Description)
Response.End
Err.Clear
End If
End Sub
'关闭表名对象
Private Sub CloseReNameTableConn()
Set objADOXDatabase = Nothing
Conn.Close
Set Conn=Nothing
End Sub
'更改数据库表名,入口参数:老表名、新表名
Public Function RenameTable(oldName, newName)
On Error Resume Next
Call ReNameTableConn
objADOXDatabase.Tables(oldName).Name = newName
If Err Then
Call ErrMsg ("更改表名错误,请手动将数据库中 <B>" & oldName & "</B> 表名更改为 < B>" & newName & "</B>,原因" & Err.Description)
Err.Clear
RenameTable = False
Else
RenameTable = True
End If
Call CloseReNameTableConn
End Function
'删除表通用函数
Public Function DelTable(TableName)
On Error Resume Next
RLConn.Execute("drop空格Table [" & TableName & "]")
If Err Then
ErrMsg ("删除 " & TableName & " 表错误,请手动将数据库中 <B>" & TableName&"</B> 表删除,原因" & Err.Description)
Err.Clear
DelTable = False
Else
DelTable = True
End If
End Function
'建立新表
Public Function CreateTable(ByVal TableName,ByVal FieldList)
Dim StrSql
If sDBType = "SQL" THen
StrSql = "CREATE TABLE [" & TableName & "]( " & FieldList & ")"
Else
StrSql = "CREATE TABLE [" & TableName & "]"
End if
RLConn.Execute(StrSql)
If Err.Number <> 0 Then
Call ErrMsg("新建 " & TableName & " 表错误,原因" & Err.Description & "")
Err.Clear()
CreateTable = False
Else
CreateTable = True
End If
End Function
'---------------------------------------数据库操作-----------------------------------------------
'建立数据库文件
Public function CreateDBfile(byVal dbFileName,byVal SavePath)
On error resume Next
SavePath = Replace(SavePath,"/","\")
If Right(SavePath,1)<>"\" Or Right(SavePath,1)<>"/" Then SavePath = Trim(SavePath) & "\"
If Left(dbFileName,1)="\" Or Left(dbFileName,1)="/" Then dbFileName = Trim(Mid(dbFileName,2,Len(dbFileName)))
If DbExists(AppPath() & SavePath & dbFileName) Then
ErrMsg("对不起,该数据库已经存在!" & AppPath() & SavePath & dbFileName)
CreateDBfile = False
Else
Response.Write AppPath() & SavePath & dbFileName
Dim Ca
Set Ca = Server.CreateObject("ADOX.Catalog")
If Err.number<>0 Then
ErrMsg("无法建立,请检查错误信息<br>" & Err.number & "<br>" & Err.Description)
Err.Clear
CreateDBfile = False
Exit function
End If
call Ca.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & AppPath() & SavePath & dbFileName)
Set Ca = Nothing
CreateDBfile = True
End If
End function
'查找数据库文件是否存在
Private function DbExists(byVal dbPath)
On Error resume Next
Dim c
Set c = Server.CreateObject("ADODB.Connection")
c.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbPath
If Err.number<>0 Then
Err.Clear
DbExists = false
else
DbExists = True
End If
set c = nothing
End function
'取当前真实路径
Private function AppPath()
AppPath = Server.MapPath("./")
If Right(AppPath,1) = "\" THen
AppPath = AppPath
ELse
AppPath = AppPath & "\"
End if
End function
'删除一个数据库文件
Public function DeleteDBFile(filespec)
filespec = AppPath() & filespec
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If Err.number<>0 Then
ErrMsg("删除文件发生错误!请查看错误信息:" & Err.number & " " & Err.Description & "<br>")
Err.Clear
DeleteDBFile = False
End If
If DbExists(filespec) THen
call fso.DeleteFile(filespec)
DeleteDBFile = True
Else
ErrMsg("删除文件发生错误!请查看错误信息:" & Err.number & " " & Err.Description & "<br>")
DeleteDBFile = False
Exit Function
End if
Set fso = Nothing
End function
'修改一个数据库名
Public function RenameDBFile(filespec1,filespec2)
filespec1 = AppPath() & filespec1:filespec2 = AppPath() & filespec2
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If Err.number<>0 Then
ErrMsg("修改文件名时发生错误!请查看错误信息:" & Err.number & " " & Err.Description)
Err.Clear
RenameDBFile = False
End If
If DbExists(filespec1) THen
call fso.CopyFile(filespec1,filespec2,True)
call fso.DeleteFile(filespec1)
RenameDBFile = True
Else
ErrMsg("源文件不存在!!!")
RenameDBFile = False
Exit Function
End if
Set fso = Nothing
End function
'压缩数据库
Public Function CompactDBFile(strDBFileName)
Dim Jet_Conn_Partial
Dim SourceConn
Dim DestConn
Dim oJetEngine
Dim oFSO
Jet_Conn_Partial = "Provider=Microsoft.Jet.OLEDB.4.0; Data source="
SourceConn = Jet_Conn_Partial & AppPath() & strDBFileName
DestConn = Jet_Conn_Partial & AppPath() & "Temp" & strDBFileName
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
Set oJetEngine = Server.CreateObject("JRO.JetEngine")
With oFSO
If Not .FileExists( AppPath() & strDBFileName) Then
ErrMsg ("数据库文件未找到!!!!" )
Stop
CompactDBFile = False
Exit Function
Else
If .FileExists( AppPath() & "Temp" & strDBFileName) Then
ErrMsg("不知道的错误!!!")
.DeleteFile ( AppPath() & "Temp" & strDBFileName)
CompactDBFile = False
Exit Function
End If
End If
End With
With oJetEngine
.CompactDatabase SourceConn, DestConn
End With
oFSO.DeleteFile AppPath() & strDBFileName
oFSO.MoveFile AppPath() & "Temp" & strDBFileName,AppPath() & strDBFileName
Set oFSO = Nothing
Set oJetEngine = Nothing
CompactDBFile = True
End Function
End Class
Dim ManDb
Set ManDb = New RLManDBCls
'//---------连接SQL数据库--------------
'ManDb.DBType = "SQL"
'ManDb.ServerName = "TAO-KUIZU"
'ManDb.UserName = "sa"
'ManDb.Password = "123456"
'ManDb.DBPath = "hhstuss"
'ManDb.CreateTable "cexo255","id int Not Null PRIMARY KEY, Name varchar(20) Not Null" '建立表(表名)
'ManDb.ReNameTable "cexo255","cexo2552" '表改名(旧表名,新表名)(用组件)
'ManDb.DelTable "cexo255" '删除表(表名)
'ManDb.AddColumn "cexo255", "Sex", "varchar(2) null" '建立表结构(表名,字段名,数据类型)
'ManDb.ModColumn "cexo255", "name", "int Not null" '修改表结构(表名,字段名,新数据类型)_
'ManDb.DelColumn "cexo255", "Sex" '删除表结构(表名,字段名)
'ManDb.AddIndex "cexo255", "i_ID", "ID" '建立表索引(表名,索引名,索引字段名)
'ManDb.DelIndex "cexo255", "i_ID" '删除表索引(表名,索引名)
'ManDb.AddPRIMARYKEY "cexo255","name" '建立表主键(表名,主键字段名)
'ManDb.DelPRIMARYKEY "cexo255","name" '删除表主键(表名,主键字段名)_
'Response.Write ManDb.GetPrimaryKey("cexo255") '取表的主键(表名)
'ManDb.upColumn "cexo255","id",12345,"name = 1" '修改字段的值
'ManDb.Execute "insert空格into cexo255(id,Name) values (2,2)" '添加记录
'ManDb.Execute "Update cexo255 Set id = 3 Where Name = 2" '修改记录
'ManDb.Execute "delete空格From cexo255 Where Name = 2" '删除记录
'ManDb.Execute("Select Count(*) From cexo255"):Response.Write ManDb.Count '统计记录个数
'If ManDb.CheckTable("StudInfo") THen Response.Write "StudInfo表存在!!!" Else Response.Write "StudInfo表不存在!!!"
'//-----------End--------------------------
'//---------连接Access数据库--------------
ManDb.DBType = "ACCESS"
ManDb.DBPath = "test.mdb"
'ManDb.CreateDBfile "test2.mdb","" '建立数据库(数据库名,保存路径)
'ManDb.DeleteDBFile("test2.mdb") '删除数据库(数据库名)
'ManDb.RenameDBFile "test2.mdb","test3.mdb" '数据库改名(旧数据库名,新数据库名)
'ManDb.CompactDBFile("test3.mdb") '压缩数据库(数据库名)
'ManDb.CreateTable "dw","" '建立表(表名)
'ManDb.ReNameTable "dw","dw2" '表改名(旧表名,新表名)(用组件)_
'ManDb.DelTable "dw" '删除表(表名)
'ManDb.AddColumn "cexo255", "name", "varchar(255) Not null" '建立表结构(表名,字段名,数据类型)
'ManDb.ModColumn "cexo255", "name", "int Not null" '修改表结构(表名,字段名,新数据类型)
'ManDb.DelColumn "cexo255", "name" '删除表结构(表名,字段名)
'ManDb.AddIndex "cexo255", "UserID", "ID" '建立表索引(表名,索引名,索引字段名)
'ManDb.DelIndex "cexo255", "UserID" '删除表索引(表名,索引名)_
'ManDb.AddPRIMARYKEY "cexo255","id" '建立表主键(表名,主键字段名)
'ManDb.DelPRIMARYKEY "cexo255","id" '删除表主键(表名,主键字段名)_
'Response.Write ManDb.GetPrimaryKey("cexo255") '取表的主键(表名)
'ManDb.upColumn "cexo255","id","12345","id = '12'" '修改字段的值
'ManDb.Execute "insert空格into cexo255(id) values ('789')" '添加记录
'ManDb.Execute "Update cexo255 Set id = 'wxf' Where id = '789'" '修改记录
'ManDb.Execute "delete空格From cexo255 Where id = 'wxf'" '删除记录
ManDb.Execute("Select Count(*) From cexo255"):Response.Write ManDb.Count '统计记录个数
'If ManDb.CheckTable("StudInfo") THen Response.Write "StudInfo表存在!!!" Else Response.Write "StudInfo表不存在!!!"
'//-----------End--------------------------
Set ManDb = Nothing
%>
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()
End If
End Sub
'执行SQL语句
Public Sub Execute(StrSql)
Set RsCount=Server.CreateObject("ADODB.RecordSet")
On Error Resume Next
RsCount = RLConn.Execute(StrSql)
If Left(StrSql,12) = "Select Count" Then Count = RsCount(0)
If Err.Number <> 0 Then
Call ErrMsg("错误提示:" & Err.Description)
Err.Clear()
End If
RsCount.Close
Set RsCount = Nothing
End Sub
'---------------------------------------索引(Index),视图(View),主键操作-----------------------------------------------
'添加字段索引
Public Function AddIndex(ByVal TableName, ByVal IndexName, ByVal ValueText)
On Error Resume Next
RLConn.Execute("CREATE INDEX " & IndexName & " ON [" & TableName & "]([" & ValueText & "])")
If Err.Number <> 0 Then
Call ErrMsg ("在 " & TableName & " 表新建" & IndexName & "索引错误,原因" & Err.Description & "请手工修改该索引。")
Err.Clear()
AddIndex = False
Else
AddIndex = True
End If
End Function
'删除表索引
Public Function DelIndex(ByVal TableName, ByVal IndexName)
On Error Resume Next
RLConn.Execute("drop空格INDEX [" & TableName & "]." & IndexName)
If Err.Number <> 0 Then
Call ErrMsg ("在 " & TableName & " 表删除" & IndexName & "索引错误,原因" & Err.Description & "请手工删除该索引。")
Err.Clear()
DelIndex = False
Else
DelIndex = True
End If
End Function
'更改表TableName的定义把字段ColumnName设为主键
Public Function AddPRIMARYKEY(ByVal TableName, ByVal ColumnName)
On Error Resume Next
TableName = Replace(Replace(TableName,"[",""),"]","")
RLConn.Execute("ALTER TABLE "& TableName & " ADD CONSTRAINT PK_"&TableName&" PRIMARY KEY (" & ColumnName & ")")
If Err.Number <> 0 Then
Call ErrMsg ("在 " & TableName & " 将字段" & ColumnName & " 添加为主键时出错,原因 " & Err.Description & "请手工修改该字段属性。")
Err.Clear()
AddPRIMARYKEY = False
Else
AddPRIMARYKEY = True
End If
End Function
'更改表TableName的定义把字段ColumnName主键的定义删除
Public Function DelPRIMARYKEY(ByVal TableName, ByVal ColumnName)
On Error Resume Next
RLConn.Execute("ALTER TABLE "& TableName & " drop空格PRIMARY KEY (" & ColumnName & ")")
If Err.Number <> 0 Then
Call ErrMsg ("在 " & TableName & " 将字段" & ColumnName & " 主键的定义删除时出错,原因" & Err.Description & "请手工修改该字段属性。")
Err.Clear()
DelPRIMARYKEY = False
Else
DelPRIMARYKEY = True
End If
End Function
'检查主键是否存在,返回该表的主键名
Function GetPrimaryKey(TableName)
on error Resume Next
Dim RsPrimary
GetPrimaryKey = ""
Set RsPrimary = RLConn.OpenSchema(28,Array(Empty,Empty,TableName))
If Not RsPrimary.Eof Then GetPrimaryKey = RsPrimary("COLUMN_NAME")
Set RsPrimary = Nothing
If Err.Number <> 0 Then
Call ErrMsg("数据库不支持检测数据表 " & TableName & " 的主键。原因 :" & Err.Description)
Err.Clear()
End If
End Function
'---------------------------------------表结构操作-----------------------------------------------
'添加新字段
Public Function AddColumn(TableName,ColumnName,ColumnType)
On Error Resume Next
RLConn.Execute("Alter Table [" & TableName & "] Add [" & ColumnName & "] " & ColumnType & "")
If Err Then
ErrMsg ("新建 " & TableName & " 表中字段错误,请手动将数据库中 <B>" & ColumnName & "</B> 字段建立,属性为 <B>"&ColumnType& "</B>,原因" & Err.Description)
Err.Clear
AddColumn = False
Else
AddColumn = True
End If
End Function
'更改字段通用函数
Public Function ModColumn(TableName,ColumnName,ColumnType)
On Error Resume Next
RLConn.Execute("Alter Table [" & TableName & "] Alter Column [" & ColumnName & "] " & ColumnType & "")
If Err Then
Call ErrMsg ("更改 " & TableName & " 表中字段属性错误,请手动将数据库中 <B>" & ColumnName & "</B> 字段更改为 <B>" & ColumnType & "</B> 属性,原因" & Err.Description)
Err.Clear
ModColumn = False
Else
ModColumn = True
End If
End Function
'删除字段通用函数
Public Function DelColumn(TableName,ColumnName)
On Error Resume Next
If sDBType = "SQL" THen
RLConn.Execute("Alter Table [" & TableName & "] drop空格Column [" & ColumnName & "]")
Else
RLConn.Execute("Alter Table [" & TableName & "] drop空格[" & ColumnName & "]")
End if
If Err Then
Call ErrMsg ("删除 " & TableName & " 表中字段错误,请手动将数据库中 <B>" & ColumnName & "</B> 字段删除,原因" & Err.Description)
Err.Clear
DelColumn = False
Else
DelColumn = True
End If
End Function
'---------------------------------------表操作---------------------------------------------------
'打开表名对象
Private Sub ReNameTableConn()
On Error Resume Next
Set objADOXDatabase = Server.CreateObject("ADOX.Catalog")
objADOXDatabase.ActiveConnection = ConnStr
If Err Then
ErrMsg("建立更改表名对象出错,您所要升级的空间不支持此对象,您很可能需要手动更改表名,原因" & Err.Description)
Response.End
Err.Clear
End If
End Sub
'关闭表名对象
Private Sub CloseReNameTableConn()
Set objADOXDatabase = Nothing
Conn.Close
Set Conn=Nothing
End Sub
'更改数据库表名,入口参数:老表名、新表名
Public Function RenameTable(oldName, newName)
On Error Resume Next
Call ReNameTableConn
objADOXDatabase.Tables(oldName).Name = newName
If Err Then
Call ErrMsg ("更改表名错误,请手动将数据库中 <B>" & oldName & "</B> 表名更改为 < B>" & newName & "</B>,原因" & Err.Description)
Err.Clear
RenameTable = False
Else
RenameTable = True
End If
Call CloseReNameTableConn
End Function
'删除表通用函数
Public Function DelTable(TableName)
On Error Resume Next
RLConn.Execute("drop空格Table [" & TableName & "]")
If Err Then
ErrMsg ("删除 " & TableName & " 表错误,请手动将数据库中 <B>" & TableName&"</B> 表删除,原因" & Err.Description)
Err.Clear
DelTable = False
Else
DelTable = True
End If
End Function
'建立新表
Public Function CreateTable(ByVal TableName,ByVal FieldList)
Dim StrSql
If sDBType = "SQL" THen
StrSql = "CREATE TABLE [" & TableName & "]( " & FieldList & ")"
Else
StrSql = "CREATE TABLE [" & TableName & "]"
End if
RLConn.Execute(StrSql)
If Err.Number <> 0 Then
Call ErrMsg("新建 " & TableName & " 表错误,原因" & Err.Description & "")
Err.Clear()
CreateTable = False
Else
CreateTable = True
End If
End Function
'---------------------------------------数据库操作-----------------------------------------------
'建立数据库文件
Public function CreateDBfile(byVal dbFileName,byVal SavePath)
On error resume Next
SavePath = Replace(SavePath,"/","\")
If Right(SavePath,1)<>"\" Or Right(SavePath,1)<>"/" Then SavePath = Trim(SavePath) & "\"
If Left(dbFileName,1)="\" Or Left(dbFileName,1)="/" Then dbFileName = Trim(Mid(dbFileName,2,Len(dbFileName)))
If DbExists(AppPath() & SavePath & dbFileName) Then
ErrMsg("对不起,该数据库已经存在!" & AppPath() & SavePath & dbFileName)
CreateDBfile = False
Else
Response.Write AppPath() & SavePath & dbFileName
Dim Ca
Set Ca = Server.CreateObject("ADOX.Catalog")
If Err.number<>0 Then
ErrMsg("无法建立,请检查错误信息<br>" & Err.number & "<br>" & Err.Description)
Err.Clear
CreateDBfile = False
Exit function
End If
call Ca.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & AppPath() & SavePath & dbFileName)
Set Ca = Nothing
CreateDBfile = True
End If
End function
'查找数据库文件是否存在
Private function DbExists(byVal dbPath)
On Error resume Next
Dim c
Set c = Server.CreateObject("ADODB.Connection")
c.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbPath
If Err.number<>0 Then
Err.Clear
DbExists = false
else
DbExists = True
End If
set c = nothing
End function
'取当前真实路径
Private function AppPath()
AppPath = Server.MapPath("./")
If Right(AppPath,1) = "\" THen
AppPath = AppPath
ELse
AppPath = AppPath & "\"
End if
End function
'删除一个数据库文件
Public function DeleteDBFile(filespec)
filespec = AppPath() & filespec
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If Err.number<>0 Then
ErrMsg("删除文件发生错误!请查看错误信息:" & Err.number & " " & Err.Description & "<br>")
Err.Clear
DeleteDBFile = False
End If
If DbExists(filespec) THen
call fso.DeleteFile(filespec)
DeleteDBFile = True
Else
ErrMsg("删除文件发生错误!请查看错误信息:" & Err.number & " " & Err.Description & "<br>")
DeleteDBFile = False
Exit Function
End if
Set fso = Nothing
End function
'修改一个数据库名
Public function RenameDBFile(filespec1,filespec2)
filespec1 = AppPath() & filespec1:filespec2 = AppPath() & filespec2
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If Err.number<>0 Then
ErrMsg("修改文件名时发生错误!请查看错误信息:" & Err.number & " " & Err.Description)
Err.Clear
RenameDBFile = False
End If
If DbExists(filespec1) THen
call fso.CopyFile(filespec1,filespec2,True)
call fso.DeleteFile(filespec1)
RenameDBFile = True
Else
ErrMsg("源文件不存在!!!")
RenameDBFile = False
Exit Function
End if
Set fso = Nothing
End function
'压缩数据库
Public Function CompactDBFile(strDBFileName)
Dim Jet_Conn_Partial
Dim SourceConn
Dim DestConn
Dim oJetEngine
Dim oFSO
Jet_Conn_Partial = "Provider=Microsoft.Jet.OLEDB.4.0; Data source="
SourceConn = Jet_Conn_Partial & AppPath() & strDBFileName
DestConn = Jet_Conn_Partial & AppPath() & "Temp" & strDBFileName
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
Set oJetEngine = Server.CreateObject("JRO.JetEngine")
With oFSO
If Not .FileExists( AppPath() & strDBFileName) Then
ErrMsg ("数据库文件未找到!!!!" )
Stop
CompactDBFile = False
Exit Function
Else
If .FileExists( AppPath() & "Temp" & strDBFileName) Then
ErrMsg("不知道的错误!!!")
.DeleteFile ( AppPath() & "Temp" & strDBFileName)
CompactDBFile = False
Exit Function
End If
End If
End With
With oJetEngine
.CompactDatabase SourceConn, DestConn
End With
oFSO.DeleteFile AppPath() & strDBFileName
oFSO.MoveFile AppPath() & "Temp" & strDBFileName,AppPath() & strDBFileName
Set oFSO = Nothing
Set oJetEngine = Nothing
CompactDBFile = True
End Function
End Class
Dim ManDb
Set ManDb = New RLManDBCls
'//---------连接SQL数据库--------------
'ManDb.DBType = "SQL"
'ManDb.ServerName = "TAO-KUIZU"
'ManDb.UserName = "sa"
'ManDb.Password = "123456"
'ManDb.DBPath = "hhstuss"
'ManDb.CreateTable "cexo255","id int Not Null PRIMARY KEY, Name varchar(20) Not Null" '建立表(表名)
'ManDb.ReNameTable "cexo255","cexo2552" '表改名(旧表名,新表名)(用组件)
'ManDb.DelTable "cexo255" '删除表(表名)
'ManDb.AddColumn "cexo255", "Sex", "varchar(2) null" '建立表结构(表名,字段名,数据类型)
'ManDb.ModColumn "cexo255", "name", "int Not null" '修改表结构(表名,字段名,新数据类型)_
'ManDb.DelColumn "cexo255", "Sex" '删除表结构(表名,字段名)
'ManDb.AddIndex "cexo255", "i_ID", "ID" '建立表索引(表名,索引名,索引字段名)
'ManDb.DelIndex "cexo255", "i_ID" '删除表索引(表名,索引名)
'ManDb.AddPRIMARYKEY "cexo255","name" '建立表主键(表名,主键字段名)
'ManDb.DelPRIMARYKEY "cexo255","name" '删除表主键(表名,主键字段名)_
'Response.Write ManDb.GetPrimaryKey("cexo255") '取表的主键(表名)
'ManDb.upColumn "cexo255","id",12345,"name = 1" '修改字段的值
'ManDb.Execute "insert空格into cexo255(id,Name) values (2,2)" '添加记录
'ManDb.Execute "Update cexo255 Set id = 3 Where Name = 2" '修改记录
'ManDb.Execute "delete空格From cexo255 Where Name = 2" '删除记录
'ManDb.Execute("Select Count(*) From cexo255"):Response.Write ManDb.Count '统计记录个数
'If ManDb.CheckTable("StudInfo") THen Response.Write "StudInfo表存在!!!" Else Response.Write "StudInfo表不存在!!!"
'//-----------End--------------------------
'//---------连接Access数据库--------------
ManDb.DBType = "ACCESS"
ManDb.DBPath = "test.mdb"
'ManDb.CreateDBfile "test2.mdb","" '建立数据库(数据库名,保存路径)
'ManDb.DeleteDBFile("test2.mdb") '删除数据库(数据库名)
'ManDb.RenameDBFile "test2.mdb","test3.mdb" '数据库改名(旧数据库名,新数据库名)
'ManDb.CompactDBFile("test3.mdb") '压缩数据库(数据库名)
'ManDb.CreateTable "dw","" '建立表(表名)
'ManDb.ReNameTable "dw","dw2" '表改名(旧表名,新表名)(用组件)_
'ManDb.DelTable "dw" '删除表(表名)
'ManDb.AddColumn "cexo255", "name", "varchar(255) Not null" '建立表结构(表名,字段名,数据类型)
'ManDb.ModColumn "cexo255", "name", "int Not null" '修改表结构(表名,字段名,新数据类型)
'ManDb.DelColumn "cexo255", "name" '删除表结构(表名,字段名)
'ManDb.AddIndex "cexo255", "UserID", "ID" '建立表索引(表名,索引名,索引字段名)
'ManDb.DelIndex "cexo255", "UserID" '删除表索引(表名,索引名)_
'ManDb.AddPRIMARYKEY "cexo255","id" '建立表主键(表名,主键字段名)
'ManDb.DelPRIMARYKEY "cexo255","id" '删除表主键(表名,主键字段名)_
'Response.Write ManDb.GetPrimaryKey("cexo255") '取表的主键(表名)
'ManDb.upColumn "cexo255","id","12345","id = '12'" '修改字段的值
'ManDb.Execute "insert空格into cexo255(id) values ('789')" '添加记录
'ManDb.Execute "Update cexo255 Set id = 'wxf' Where id = '789'" '修改记录
'ManDb.Execute "delete空格From cexo255 Where id = 'wxf'" '删除记录
ManDb.Execute("Select Count(*) From cexo255"):Response.Write ManDb.Count '统计记录个数
'If ManDb.CheckTable("StudInfo") THen Response.Write "StudInfo表存在!!!" Else Response.Write "StudInfo表不存在!!!"
'//-----------End--------------------------
Set ManDb = Nothing
%>
标签:
在线管理数据库,类
天枫庄资源网 Design By www.wosibo.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
天枫庄资源网 Design By www.wosibo.com
暂无在线管理数据库 类的评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
2024年12月24日
2024年12月24日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]