<%
'======================
'@描述:数据库操作类
'@类名:db
'@日期:2006-10-31
'@作者:NqIceCoffee
'======================
Class cls_db
Private Conn '数据库连接(Connection)
Private Rs '数据集(RecordSet)
Private DbName '数据库名称(String)
Public IsErr '执行过程中是否出现错误(Boolen)
Public ErrMessage '执行过程中的错误消息(String)
Private Sub Class_Initialize()
Set Conn = Server.CreateObject("Adodb.Connection")
Set Rs = Server.CreateObject("Adodb.RecordSet")
IsErr = False
ErrMessage = ""
End Sub
Private Sub Class_Terminate()
Conn.Close()
End Sub
Public Property Let setDataBaseName(str)
DbName = str
End Property
Public Sub OpenConn()
On Error Resume Next
Conn.Open "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & Server.MapPath(DbName)
If Err Then
IsErr = True
ErrMessage = ErrMessage & "<li><b>错误代码</b>:" & Err.Number & "。<b>描述</b>:" & Err.Description & "</li>"
Err.Clear()
End If
End Sub
Public Function Exec(sql)
Dim RowsAffect
On Error Resume Next
Call Conn.Execute(sql,RowsAffect,&h0001)
If Err Then
IsErr = True
ErrMessage = ErrMessage & "<li><b>错误代码</b>:" & Err.Number & "。<b>描述</b>:" & Err.Description & "</li>"
Err.Clear()
RowsAffect = Null
End If
Exec = RowsAffect
End Function
Public Function GetColumn(sql)
Dim returnValue
On Error Resume Next
returnValue = Conn.Execute(sql,,&h0001)(0)
If Err Then
IsErr = True
ErrMessage = ErrMessage & "<li><b>错误代码</b>:" & Err.Number & "。<b>描述</b>:" & Err.Description & "</li>"
Err.Clear()
returnValue = Null
End If
GetColumn = returnValue
End Function
Public Function Query(sql,dataStart,recordNum)
Dim QueryArray
On Error Resume Next
Rs.Open sql,Conn,1,1,&h0001
If Err Then
IsErr = True
ErrMessage = ErrMessage & "<li><b>错误代码</b>:" & Err.Number & "。<b>描述</b>:" & Err.Description & "</li>"
Err.Clear()
Query = Null
Exit Function
Else
If Rs.Eof Then
Rs.Close()
Query = Null
Exit Function
Else
Rs.AbsolutePosition = Int(dataStart)
Query = Rs.getRows(recordNum)
Rs.Close()
End If
End If
End Function
End Class
%>
这个是我的数据库操作类
刚完成,呵呵,如果不用在大一点的项目中,感觉它是鸡肋.
'======================
'@描述:数据库操作类
'@类名:db
'@日期:2006-10-31
'@作者:NqIceCoffee
'======================
Class cls_db
Private Conn '数据库连接(Connection)
Private Rs '数据集(RecordSet)
Private DbName '数据库名称(String)
Public IsErr '执行过程中是否出现错误(Boolen)
Public ErrMessage '执行过程中的错误消息(String)
Private Sub Class_Initialize()
Set Conn = Server.CreateObject("Adodb.Connection")
Set Rs = Server.CreateObject("Adodb.RecordSet")
IsErr = False
ErrMessage = ""
End Sub
Private Sub Class_Terminate()
Conn.Close()
End Sub
Public Property Let setDataBaseName(str)
DbName = str
End Property
Public Sub OpenConn()
On Error Resume Next
Conn.Open "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & Server.MapPath(DbName)
If Err Then
IsErr = True
ErrMessage = ErrMessage & "<li><b>错误代码</b>:" & Err.Number & "。<b>描述</b>:" & Err.Description & "</li>"
Err.Clear()
End If
End Sub
Public Function Exec(sql)
Dim RowsAffect
On Error Resume Next
Call Conn.Execute(sql,RowsAffect,&h0001)
If Err Then
IsErr = True
ErrMessage = ErrMessage & "<li><b>错误代码</b>:" & Err.Number & "。<b>描述</b>:" & Err.Description & "</li>"
Err.Clear()
RowsAffect = Null
End If
Exec = RowsAffect
End Function
Public Function GetColumn(sql)
Dim returnValue
On Error Resume Next
returnValue = Conn.Execute(sql,,&h0001)(0)
If Err Then
IsErr = True
ErrMessage = ErrMessage & "<li><b>错误代码</b>:" & Err.Number & "。<b>描述</b>:" & Err.Description & "</li>"
Err.Clear()
returnValue = Null
End If
GetColumn = returnValue
End Function
Public Function Query(sql,dataStart,recordNum)
Dim QueryArray
On Error Resume Next
Rs.Open sql,Conn,1,1,&h0001
If Err Then
IsErr = True
ErrMessage = ErrMessage & "<li><b>错误代码</b>:" & Err.Number & "。<b>描述</b>:" & Err.Description & "</li>"
Err.Clear()
Query = Null
Exit Function
Else
If Rs.Eof Then
Rs.Close()
Query = Null
Exit Function
Else
Rs.AbsolutePosition = Int(dataStart)
Query = Rs.getRows(recordNum)
Rs.Close()
End If
End If
End Function
End Class
%>
这个是我的数据库操作类
刚完成,呵呵,如果不用在大一点的项目中,感觉它是鸡肋.
帮助别人,提高自己!