此类个人觉得是很有用的!!!对于以后提交表单数据,不用再一个一个去写了,直接引用该类,再SAVE或EDIT即可,简单多了,但当然,因为它不是智能的,所以对于某些数据格式是不能做核查的!!使用示例代码如下:
<%
Dim action
action=Request("action")
If action="save" Then
Dim objClass
Set objClass=New SaveFormData
objClass.MDBFile=Server.Mappath("data/data.mdb")
'objClass.SaveRecord "number","*","id"
objClass.SaveRecord "number","Num1,text",""
'objClass.EditRecord "number","*","id=15","id"
Set objClass=Nothing
End If
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
Private Sub Class_Initialize
C_Conn=Null
C_NumericAllowNull=True
C_DateTimeAllowNull=True
End Sub
Private Sub Class_Terminate
If Not IsNothing(C_Conn) Then
C_Conn.Close
Set C_Conn=Nothing
End If
End Sub
'/***************************************************************************
'/* 设置/返回Conn对象
'/*说明:添加这个是为了其它数据库(如:MSSQL)
'/***************************************************************************
Public Property Set Conn(sNewValue)
On Error Resume Next
If Not IsNothing(sNewValue) Then
C_Conn.Close
Set C_Conn=Nothing
End If
Set C_Conn=sNewValue
End Property
Public Property Get Conn
If Not IsNothing(C_Conn) Then
Set Conn=C_Conn
Else
Conn=Null
End If
End Property
'/***************************************************************************
'/* 设置/返回数据库文件
'/*说明:
'/***************************************************************************
Public Property Let MDBFile(sNewValue)
If Trim(sNewValue)<>C_MDBFile Then '如果数据库文件改变则重新建立CONN对象
C_MDBFile=Trim(sNewValue)
Call ReCreateConn
End If
End Property
Public Property Get MDBFile
MDBFile=C_MDBFile
End Property
'/***************************************************************************
'/* 设置/返回错误代码
'/*说明:
'/***************************************************************************
Public Property Get ErrNumber
ErrNumber=C_ErrNumber
End Property
Public Sub ClearErr
C_ErrNumber=0
End Sub
'/***************************************************************************
'/* 设置/返回NumericAllowNull(数值型字段是否允许空值)
'/*说明:
'/***************************************************************************
Public Property Let NumericAllowNull(sNewValue)
C_NumericAllowNull=CBool(sNewValue)
End Property
Public Property Get NumericAllowNull
NumericAllowNull=C_NumericAllowNull
End Property
'/***************************************************************************
'/* 设置/返回DateTimeAllowNull(数值型字段是否允许空值)
'/*说明:
'/***************************************************************************
Public Property Let DateTimeAllowNull(sNewValue)
C_DateTimeAllowNull=CBool(sNewValue)
End Property
Public Property Get DateTimeAllowNull
DateTimeAllowNull=C_DateTimeAllowNull
End Property
'/***************************************************************************
'/* 通过数据库的所有字段表进行获取数据并保存
'/*说明:sTable = 表名 sFields = 要保存的字段名 NotFields = 不保存的字段名
'/***************************************************************************
Public Function SaveRecord(ByVal sTable,ByVal sFields,ByVal NotFields)
On Error Resume Next
Dim Rs,i,sText,sItem
Dim dArray()
Call InitConn
If IsNull(C_Conn) Then
ErrNumber = 1 'ErrNumber = 1 保存数据进数据库时出未知错误
SaveRecord=False
Exit Function
End If
Set Rs = server.CreateObject("ADODB.Recordset")
If Trim(sFields)="" Then sFields="*"
NotFields=","&NotFields&","