如何用ASP类实现通用页面读写数据库

司空明达 2005-07-20 04:32:33
ASP能不能用类实现这样的效果.我希望达到的效果是由一个类文件统一读写数据.其它的文件只要向类文件提供字段名和控件名即可读写,而不用考虑SQL语法.而类文件本身不考虑数据库结构.
...全文
168 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
ice241018 2006-06-22
  • 打赏
  • 举报
回复
学习
司空明达 2005-08-01
  • 打赏
  • 举报
回复
那有没有更好的方法啊?
zhoujiamurong 2005-07-27
  • 打赏
  • 举报
回复
楼上的还是要对应的数据库结构才可
司空明达 2005-07-26
  • 打赏
  • 举报
回复
继续等待
caobin518 2005-07-25
  • 打赏
  • 举报
回复
public sub addnewitemkind(itemkindname,contactpic,itemkindformshow)
set MyCommand=server.createobject("adodb.command")
Set MyCommand.ActiveConnection=conn
MyCommand.CommandType=4
MyCommand.CommandText="addnewitemkind"
Set MyParam=MyCommand.CreateParameter("itemkindname",200,1,50,itemkindname)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("contactpic",3,1,4,contactpic)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("itemkindformshow",200,1,50,itemkindformshow)
MyCommand.Parameters.Append Myparam
MyCommand.Execute
set MyCommand=nothing
end sub

public sub addnewitem(itemkind,itemname,itemprice,itemurl,contactpic,itemshow)
set MyCommand=server.createobject("adodb.command")
Set MyCommand.ActiveConnection=conn
MyCommand.CommandType=4
MyCommand.CommandText="addnewitem"
Set MyParam=MyCommand.CreateParameter("itemkind",3,1,4,itemkind)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("itemname",200,1,50,itemname)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("itemprice",3,1,4,itemprice)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("itemurl",200,1,50,itemurl)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("contactpic",3,1,4,contactpic)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("itemshow",200,1,50,itemshow)
MyCommand.Parameters.Append Myparam
MyCommand.Execute
set MyCommand=nothing
end sub

public sub deletepicprice(picpricenum)
set MyCommand=server.createobject("adodb.command")
Set MyCommand.ActiveConnection=conn
MyCommand.CommandType=4
MyCommand.CommandText="deletepicprice"
Set MyParam=MyCommand.CreateParameter("picpricenum",3,1,4,picpricenum)
MyCommand.Parameters.Append Myparam
MyCommand.Execute
set MyCommand=nothing
end sub

public sub deleteitemkind(itemkind)
set MyCommand=server.createobject("adodb.command")
Set MyCommand.ActiveConnection=conn
MyCommand.CommandType=4
MyCommand.CommandText="deleteitemkind"
Set MyParam=MyCommand.CreateParameter("itemkind",3,1,4,itemkind)
MyCommand.Parameters.Append Myparam
MyCommand.Execute
set MyCommand=nothing
end sub

public sub deleteitem(itemnum)
set MyCommand=server.createobject("adodb.command")
Set MyCommand.ActiveConnection=conn
MyCommand.CommandType=4
MyCommand.CommandText="deleteitem"
Set MyParam=MyCommand.CreateParameter("itemnum",3,1,4,itemnum)
MyCommand.Parameters.Append Myparam
MyCommand.Execute
set MyCommand=nothing
end sub

public sub edititemkind(itemkind,itemkindname,contactpic,itemkindformshow)
set MyCommand=server.createobject("adodb.command")
Set MyCommand.ActiveConnection=conn
MyCommand.CommandType=4
MyCommand.CommandText="edititemkind"
Set MyParam=MyCommand.CreateParameter("itemkind",3,1,4,itemkind)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("itemname",200,1,50,itemname)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("contactpic",3,1,4,contactpic)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("itemkindformshow",200,1,50,itemkindformshow)
MyCommand.Parameters.Append Myparam
MyCommand.Execute
set MyCommand=nothing
end sub

public sub edititem(itemkind,itemname,itemprice,itemurl,contactpic,itemnum,itemshow)
set MyCommand=server.createobject("adodb.command")
Set MyCommand.ActiveConnection=conn
MyCommand.CommandType=4
MyCommand.CommandText="edititem"
Set MyParam=MyCommand.CreateParameter("itemkind",3,1,4,itemkind)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("itemname",200,1,50,itemname)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("itemprice",3,1,4,itemprice)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("itemurl",200,1,50,itemurl)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("contactpic",3,1,4,contactpic)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("itemnum",3,1,4,contactpic)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("itemshow",200,1,50,itemshow)
MyCommand.Parameters.Append Myparam
MyCommand.Execute
set MyCommand=nothing
end sub



end class
</script>
caobin518 2005-07-25
  • 打赏
  • 举报
回复
public function queryitemkind(contactpic)
set rs=server.createobject("adodb.recordset")
set MyCommand=server.createobject("adodb.command")
Set MyCommand.ActiveConnection=conn
MyCommand.CommandType=4
MyCommand.CommandText="queryitemkind"
Set MyParam=MyCommand.CreateParameter("contactpic",3,1,4,contactpic)
MyCommand.Parameters.Append Myparam
MyCommand.Execute
rs.open MyCommand,conn,1,3
set queryitemkind=rs
set MyCommand=nothing
set rs=nothing
end function

public function queryitem(itemkind)
set rs=server.createobject("adodb.recordset")
set MyCommand=server.createobject("adodb.command")
Set MyCommand.ActiveConnection=conn
MyCommand.CommandType=4
MyCommand.CommandText="queryitem"
Set MyParam=MyCommand.CreateParameter("itemkind",3,1,4,itemkind)
MyCommand.Parameters.Append Myparam
MyCommand.Execute
rs.open MyCommand,conn,1,3
set queryitem=rs
set MyCommand=nothing
set rs=nothing
end function

public function querypicall()
set rs=server.createobject("adodb.recordset")
set MyCommand=server.createobject("adodb.command")
Set MyCommand.ActiveConnection=conn
MyCommand.CommandType=4
MyCommand.CommandText="querypicall"
MyCommand.Execute
rs.open MyCommand,conn,1,3
set querypicall=rs
set MyCommand=nothing
set rs=nothing
end function

public function querypicpricesingle(picpricenum)
set rs=server.createobject("adodb.recordset")
set MyCommand=server.createobject("adodb.command")
Set MyCommand.ActiveConnection=conn
MyCommand.CommandType=4
MyCommand.CommandText="querypicpricesingle"
Set MyParam=MyCommand.CreateParameter("picpricenum",3,1,4,picpricenum)
MyCommand.Parameters.Append Myparam
MyCommand.Execute
rs.open MyCommand,conn,1,3
set querypicpricesingle=rs
set MyCommand=nothing
set rs=nothing
end function

public sub addpicprice(picsize,length,width,picprice,showyn,showform,sequence)
set MyCommand=server.createobject("adodb.command")
Set MyCommand.ActiveConnection=conn
MyCommand.CommandType=4
MyCommand.CommandText="addnewitemkind"
Set MyParam=MyCommand.CreateParameter("picsize",200,1,50,picsize)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("length",3,1,4,length)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("width",3,1,4,width)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("picprice",,1,4,picprice)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("showyn",3,1,4,showyn)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("showform",200,1,50,showform)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("sequence",3,1,4,sequence)
MyCommand.Parameters.Append Myparam

MyCommand.Execute
set MyCommand=nothing
end sub
caobin518 2005-07-25
  • 打赏
  • 举报
回复
<script language="vbscript" runat="server">
class oprdbase
Private Sub Class_Initialize
Set conn=server.CreateObject ("adodb.connection")
strConn="driver={SQL Server};server=192.168.0.2;uid=sa;Pwd=;database=website"
conn.open strConn
End Sub

public function querypurview(user_name,pwd) '查询权限
set MyCommand=server.createobject("adodb.command")
Set MyCommand.ActiveConnection=conn
MyCommand.CommandType=4
MyCommand.CommandText="querypurview"
Set MyParam=MyCommand.CreateParameter("username",200,1,50,user_name)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("pwd",200,1,50,pwd)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("right",3,2,4)
MyCommand.Parameters.Append Myparam
MyCommand.Execute
right=MyCommand("right")
set MyCommand=nothing
querypurview=right
end function

public function queryorder(ordercode,dengji)
set rs=server.createobject("adodb.recordset")
set MyCommand=server.createobject("adodb.command")
Set MyCommand.ActiveConnection=conn
MyCommand.CommandType=4
MyCommand.CommandText="queryordercode"
Set MyParam=MyCommand.CreateParameter("ordercode",3,1,4,ordercode)
MyCommand.Parameters.Append Myparam
Set MyParam=MyCommand.CreateParameter("dengji",3,1,4,dengji)
MyCommand.Parameters.Append Myparam
MyCommand.Execute
rs.open MyCommand,conn,1,3
set queryorder=rs
set MyCommand=nothing
set rs=nothing
' right=MyCommand("right")
' set MyCommand=nothing
end function
司空明达 2005-07-25
  • 打赏
  • 举报
回复
谢谢!
不过,我不单指连接数据库,我想把INSERT\UPDATE\DELETE\SELETE等都放在类里实现!
  • 打赏
  • 举报
回复
'******************************
'名称: ConnectionDataBase
'参数:DataBase,p_dbUserID,p_dbPassword,p_dbType
'返回值:NULL
'作用:连接到数据库
'创建时间:2005年5月6日
'******************************
Public Function ConnectionDataBase(param_DataBase,param_dbUserID,param_dbPassword,param_dbType)
If Not p_Debug Then On Error Resume Next
ClientConnected
If IsNumeric(param_dbType) Then
Set objConn=Server.CreateObject("ADODB.Connection")
objConn.ConnectionTimeOut=10 '设置连接超时为10秒
dbPath=Server.MapPath(p_dbFolder¶m_DataBase)
'Response.Write dbPath
Select Case param_dbType
Case 11: 'Access Data Base(OLEDB)
ConnStr="Provider=Microsoft.Jet.Oledb.4.0;Data Source="&dbPath&";User ID="¶m_dbUserID&";Password="¶m_dbPassword&""
Case 21: 'SQL Server (OLEDB)
ConnStr="Provider=SQLOLEDB;Initial Catalog="¶m_DataBase&";Data Source="&p_sqlDataSource&";User ID="¶m_dbUserID&";Password="¶m_dbPassword&""
Case 12: 'Access Data Base(ODBC)
ConnStr="Driver={Microsoft Access Driver (*.mdb)};DBQ="&dbPath&";User ID="¶m_dbUserID&";Password="¶m_dbPassword
Case 22: 'SQL Server (ODBC)
ConnStr="Driver={SQL Server};DataBase="¶m_DataBase&";Server="&p_sqlDataSource&";User ID="¶m_dbUserID&";Password="¶m_dbPassword&""
Case Else:
AddErrorCode(100)
If p_Debug Then Response.Write ShowErrMsg()
'Exit Function
End Select
objConn.ConnectionString=ConnStr
objConn.Open
Set ConnectionDataBase=objConn
If Err Then
Err.Clear

If SaveLog Then
tmpMsg="数据库连接时出现错误,请检查您的查询代码是否正确。<br>基于安全的理由,只显示本信息,要查看详细的错误信息,请设置dsj.Debug=True"
cmd="Execute the command of :"¶m_dbtype
Response.Write SaveSQLLog(cmd,tmpMsg)
Else
Response.Write "数据库连接时出现错误,请检查您的查询代码是否正确。"
End If
AddErrorCode(101)
Set objConn=Nothing
Response.End()
End If
End If
End Function
司空明达 2005-07-25
  • 打赏
  • 举报
回复
没有人知道吗?
司空明达 2005-07-25
  • 打赏
  • 举报
回复
谢谢!
另外能不能提供相应的注解或者调用类的文件?

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧