上一篇:如何准确定时运行ASP文件 >>
ASP整合的一个SQL语句类
下面让我们看看这个类的代码:
<%
class SQLString
‘’************************************
‘’变量定义
‘’************************************
‘’sTableName ---- 表名
‘’iSQLType ----SQL语句类型:0-增加,1-更新,2-删除,3-查询
‘’sWhere ---- 条件
‘’sOrder ---- 排序方式
‘’sSQL ----值
Private sTableName,iSQLType,sWhere,sOrder,sSQL
‘’************************************
‘’类初始化/结束
‘’************************************
Private Sub Class_Initialize()
sTableName=""
iSQLType=0
sWhere=""
sOrder=""
sSQL=""
End Sub
Private Sub Class_Terminate()
End Sub
‘’************************************
‘’属性
‘’************************************
‘设置表名的属性
Public Property Let TableName(value)
sTableName=value
End Property
‘设置条件
Public Property Let Where(value)
sWhere=value
End Property
‘设置排序方式
Public Property Let Order(value)
sOrder=value
End Property
‘设置查询语句的类型
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
‘’************************************
‘’函数
‘’************************************
‘’增加字段(字段名称,字段值)
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
‘’返回SQL语句
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
‘’清空语句
Public Sub Clear()
sTableName=""
iSQLType=0
sWhere=""
sOrder=""
sSQL=""
End Sub
end class
%>
使用方法:
例句:insert into message (incept,sender,title,content,sendtime,flag,issend) values (‘’"&incept(i)&"‘’,‘’"&membername&"‘’,‘’"&title&"‘’,‘’"&message&"‘’,Now(),0,1)
set a =new SQLString ‘创建类对象
a.TableName=" message " ‘设置表名为message
a.SQLType=0 ‘设置查询类型为增加记录
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
下一篇:Jmail发信的实例,模块化随时调用 >>
相关文章:
- · 下载网页中的所有资源
- · 函数方便制作管理界面
- · 无限级目录树+记忆节点状态
- · 利用C#在SQL Server2000存取图像 For Window
- · 通过MSXML2自动获取QQ个人头像及在线情况(给初学者)
- · ASP模板类[实现一维循环和二维循环,可以从文件、数据库、变量取摸板]
- · 各种存储过程使用指南
- · 树型结构在ASP中的简单解决
- · 用ASPJPEG组件制作图片的缩略图和加水印
- · 用asp制作强大的搜索引擎(一)
- · VBscript和javascript的选择
- · 在ASP中使用SQL语句之2:用WHERE子句设置查询条件
- · 在线压缩WINRAR文件
- · 在线解压缩上传的WINRAR文件
- · 用javascript实现的日历
- · 在表单里使用”post”和”get”有什么区别
- · 如何把ASP编写成DLL
- · ASP计数器设计详解(转载)
- · 统计在线人数、每日访问人数和总人数
- · 如何动态ASP文件
- · 用asp打开光驱!
- · asp分页显示详论
- · 面向对象的ASP技术:思考与实践
- · 如何获得真实的ip
- · 对文件夹操作2
- · 对文件的操作1
- · 全面优化ASP应用程序的性能(转载)
- · 测试访问者电脑的分辨率
- · 让你的ASP运行于非Windows平台
- · 用ASP编程实现快速查找
- · Calculator
- · ASP导出Excel数据的四种方法
- · ASP编程中15个非常有用的例子
- · 改进ASP应用程序中的字符串处理性能
- · 保护你的ASP页面的两种办法
- · ASP如何获取真实IP地址
- · 关于<SELECT>的无限级联(省|市|县|乡|村|...)
- · 一个简单的计数器和流量统计程序
