Recommended: ASP template code Class Template Private m_FileName, m_Root, m_Unknowns, m_LastError, m_HaltOnErr Private m_ValueList, m_BlockList Private m_RegExp Private Sub Class_Initialize Set m_ValueList = CreateObject(Scripting.Dictionary) Set m_BlockList = CreateObject(Script
When writing an asp database program, we usually use SQL statements, and when adding and updating data, we usually use the following method: insert into message (incept,sender,title,content,sendtime,flag,issend) values ('&incept(i)&','&membername&','&title&','&message&',Now(),0,1) When there are many fields and many updated tables, it will be more troublesome to modify and find errors. After using this SQL class, it can be simplified and it is easier to check errors. Adding field names and field values through the AddField function of the class can easily insert field names and field values into SQL statements and then return the SQL statement.
Let's take a look at the code of this class:
<%
class SQLString
'***************************************
'Variable definition
'***************************************
'sTableName --- Table name
'iSQLType --- SQL statement type: 0-add, 1-update, 2-delete, 3-query
'sWhere --- Conditions
'sOrder --- Sort by
'sSQL ----value
PRivate sTableName,iSQLType,sWhere,sOrder,sSQL
'***************************************
'Class initialization/end
'***************************************
Private Sub Class_Initialize()
sTableName=
iSQLType=0
sWhere=
sOrder=
sSQL=
End Sub
Private Sub Class_Terminate()
End Sub
'***************************************
'property
'***************************************
'Set the properties of the table name
Public Property Let TableName(value)
sTableName=value
End Property
'Set the conditions
Public Property Let Where(value)
sWhere=value
End Property
'Set the sorting method
Public Property Let Order(value)
sOrder=value
End Property
'Set the type of query statement
Public property Let SQLType(value)
iSQLType=value
select case iSQLType
case 0
sSQL=insert into #0 (#1) values (#2)
case 1
sSQL=update #0 set #1=#2
case 2
sSQL=delete from #0
case 3
sSQL=select #1 from #0
end select
End Property
'***************************************
'function
'***************************************
'Add field (field name, field value)
Public Sub AddField(sFieldName,sValue)
select case iSQLType
case 0
sSQL=replace(sSQL,#1,sFieldName &,#1)
sSQL=replace(sSQL,#2,' & sFieldName & ',#2)
case 1
sSQL=replace(sSQL,#1,sFieldName)
sSQL=replace(sSQL,#2,' & sFieldName & ',#1=#2)
case 3
sSQL=replace(sSQL,#1,sFieldName &,#1)
End Select
End Sub
'Return SQL statement
Public Function ReturnSQL()
sSQL=replace(sSQL,#0,sTableName)
select case iSQLType
case 0
sSQL=replace(sSQL,,#1,)
sSQL=replace(sSQL,,#2,)
case 1
sSQL=replace(sSQL,,#1=#2,)
case 3
sSQL=replace(sSQL,,#1,)
end Select
if sWhere<> then
sSQL=sSQL & where & sWhere
end if
if sOrder<> then
sSQL=sSQL & order by & sOrder
end if
ReturnSQL=sSQL
End Function
'Clear statement
Public Sub Clear()
sTableName=
iSQLType=0
sWhere=
sOrder=
sSQL=
End Sub
end class
%>
How to use:
Example: insert into message (incept,sender,title,content,sendtime,flag,issend) values ('&incept(i)&','&membername&','&title&','&message&',Now(),0,1)
set a =new SQLString 'Create class object
a.TableName= message 'Set the table name as message
a.SQLType=0 'Set the query type to add record
a.AddField incept, incept(i)
a.AddField sender , membername
a.AddField title , membername
a.AddField sender , title
a.AddField content , message
a.AddField sendtime , sendtime()
a.AddField flag, 0
a.AddField issend , 1
Response.Write a.ReturnSQl
set a=nothing
Share: Calendar program produced by asp A pure ASP-created calendar program can beautified by itself, and only the simplest CSS style is available here. . . style body{font-size:12px; margin:20px 0 0 20px; padding:0} tr,td{text-align:center;} /style % '================================================================================================================================================================= 'Description: Calendar file'=====================================================================================================================