ASP saves data to access database code

Source: Internet
Author: User
Tags access database

Database Connection Code

<%
Dbname= "Chatroom.mdb"
Set Conn=server.createobject ("Adodb.connection")
Connstr= "dbq=" +server.mappath (dbname) + ";d river={microsoft Access Driver (*.mdb)};"
Conn.Open ConnStr
%>


HTML page code

<title>postmsg</title>
<body topmargin= "0" leftmargin= "0" >
<table width= "100%" height= "border=" "0" >
<tr>
&LT;TD height= "colspan=" 2 ">
<form action= "postmsg.asp?act=addmsg&myself=<%=request.querystring (" Myself ")%>&toname=<%= Request.QueryString ("ToName")%> "method=" Post "Name=" Form1 ">
<input readonly type=text name=fromname value= "<%=request.querystring (" Myself ")%>" >
Right
<select name= "Rname" >
<%if request.querystring ("toname") = "" Then%>
<option> everyone </option>
<%else%>
<option><%=request.querystring ("ToName")%></option>
<%end if
' Show number online
Set Rsout=server.createobject ("Adodb.recordset")
Sqlout= "SELECT * from online where ID order by id desc" ' All records are checked from data bitterness, sorted by ID
Rsout.open sqlout,conn,1,1 ' Execute query to save results in Rsout
For I=1 to 50 ' displays up to 50 user names in the dropdown box
%>
<option><%response.write (Rsout ("username"))%></option>
<%
Rsout.movenext ' points to the next record
If rsout.eof then exit for ' gets to the last record then jumps out for loop
Next
%>
</select>
Said:
<input name= "MSG" type= "text" size= ">"
<input name= "Submit" type= "submitted" value= "Submission" height= ">
<input name= "hidden" type= "submit" value= "Private Chat" >
<input name= "username" type= "hidden" id= "username" value= "<%response.write (Request.QueryString (" myself "))% > ">
</form>
</td>
</tr>
<tr>
&LT;TD width= "602" height= "></td>"
&LT;TD width= "185" ></td>
</tr>
</table>
</body>

Processing pages can be saved on the same page

<%
ac=request.querystring ("act") ' reads the value of the Act
The value of the If ac= "addmsg" then act is addmsg
If Request.Form ("hidden") <> "then" private chat
Session ("chat") = "" Empty the contents of the session ("chat")
' Keep the private chat information to be displayed in application (' chat ')
Application ("chat") = "<font size = 2>" &request.form ("username") & "Quietly to" &request.form ("Rname") & "said: <font color= black>" &request.form ("MSG") & "</font>" &time () & "</font>"
Application ("Chatto") =request.form ("rname") ' Chat object
Application ("owner") =request.form ("username") ' speaker
Else ' is not a private conversation
Set Rs=server.createobject ("Adodb.recordset") ' Creates a Recordset object
Sql= "SELECT * from chat" Query database
Rs.Open sql,conn,1,3 ' Execute query
Rs.addnew ' Add a new record
RS ("FromName") =request.form ("username") ' speaker
RS ("ToName") =request.form ("rname") ' Chat object
Private chat information displayed by RS ("chat") =request.form ("MSG")
RS ("Posttime") =time () ' Submit time
Rs.update
Rs.close
Set rs=nothing
' Add a chat record and add the value of application (' Gchatnum ') to 1
Application ("Gchatnum") =application ("Gchatnum") +1
End If
End If
%>

SOURCE Download Address

Http://down.111cn.net/down/code/asp/2010/1024/21402.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.