一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

asp保存数据到access数据库代码

时间:2010-10-24 编辑:简简单单 来源:一聚教程网

数据库连接代码

<%
dbname="chatroom.mdb"
set conn=server.createobject("adodb.connection")
connstr="dbq="+server.mappath(dbname)+";driver={microsoft access driver (*.mdb)};"
conn.open connstr
%>


html页面代码



 postmsg



 
  
 
 
  
  
 

  
&toname=<%=request.querystring("toname")%>" method="post" name="form1">
   ">
   对
   
   说:
   
   
   
   ">
  

  



处理页面可保存在同一页面

<%
ac=request.querystring("act")   '读取act 的值
if ac="addmsg" then   'act的值为addmsg
 if request.form("hidden")<>"" then   '私聊
  session("chat")=""   '清空session("chat")中的内容
  '把要显示的私聊信息保存在application("chat")中
  application("chat")=""&request.form("username")&"悄悄地对"&request.form("rname")&"说:"&request.form("msg")&""&time()&""
  application("chatto")=request.form("rname")   '聊天对象
  application("owner")=request.form("username")   '发言者
 else   '不是私聊
  set rs=server.createobject("adodb.recordset")   '创建recordset对象
  sql="select * from chat"   '查询数据库
  rs.open sql,conn,1,3   '执行查询
  rs.addnew   '添加一条新记录
  rs("fromname")=request.form("username")   '发言者
  rs("toname")=request.form("rname")   '聊天对象
  rs("chat")=request.form("msg")   '显示的私聊信息
  rs("posttime")=time()   '提交时间
  rs.update
  rs.close
  set rs=nothing
  '增加一条聊天记录,将application("gchatnum")的值加1
  application("gchatnum")=application("gchatnum")+1
 end if
end if
%>

源码下载地址

http://down.111com.net/down/code/asp/2010/1024/21402.html

热门栏目