Learn the ASP useful code

Source: Internet
Author: User
Tags expression table name root directory

<% @language =vbscript%>
<%
Dimconn,mdbfile
Mdbfile=server.mappath ("database name. mdb")
Setconn=server.createobject ("Adodb.connection")
Conn.Open "Driver={microsoftaccessdriver (*.mdb)};uid=admin;pwd= database password; dbq=" &mdbfile

%>

<% @language =vbscript%>
<%
Dimconn
Setconn=server.createobject ("Adodb.connection")
Con.open "Provider=sqloledb;datasource=sql server name or IP address; Uid=sa; pwd= database password; database= database name
%>

"Driver={microsoftaccessdriver (*.mdb)};D absolute path to bq= database"

When you are done, open the database server and

"Driver={microsoftaccessdriver (*.mdb)};D absolute path to bq= database"

Into

"Provider=microsoft.jet.oledb.4.0;datasource=" &server.mappath ("database path under Server root directory")

and modify the local server into a test server

<!--#includefile = "path and name of page"-->

<%=rs ("field")%>

Response.Write ("literal or string");

Setconn=server. CreateObject ("Adodb.connection")
Conn.Open "Provider=microsoft.jet.oledb.4.0;datasource=" &server. MapPath ("***/photodata.mdb") ' Change your database file storage path
Setrs=server.createobject ("Adodb.recordset") ' Set up a dataset
Sql= "Select*fromdata" To change your database table name
Rs. opensql,conn,1,1

<%=now ()%>

<%=request.servervariables ("Remote_host")%>

<%randomize%>
<%= (int (rnd () *n) +1)%>
N is a number that can be changed

Response.Redirect ("page")

Response.Write ("<script>alert") (' message box! ') </script> ")

<%formmethod= "POST" action= "mynextpage.asp" >
<%foreachiteminrequest.form%>
<inputnamee= "<%=item%>" type= "HIDDEN"
Value= "<%=server. HTMLEncode (Request.Form (item))%> ">
<%next%>
</form>

(1) Data record filtering:

sql= "select*from data table where field name = field value by field name [desc]"

sql= "select*from data table where field name like '% field value% ' By field name [desc]"

sql= "selecttop10*from data table where field name by field name [desc]"

sql= "select*from data table where field name in (' Value 1 ', ' Value 2 ', ' Value 3 ')"

sql= "select*from data table where field name between value 1and value 2"

(2) Update data records:

sql= "Update data table set field name = field value where Condition expression"

Sql= Update data Table set field 1= value 1, field 2= value 2 ... Field n= value nwhere conditional expression "

(3) Delete data records:

sql= "deletefrom data table where condition expression"

sql= "Deletefrom data table" (delete all records in datasheet)

(4) Adding data records:

Sql= "Insertinto Datasheet (field 1, Field 2, Field 3 ...) Valuess (value 1, value 2, value 3 ...) "

Sql= "Insertinto target datasheet select*from source data Table" (Add a record from the source data table to the destination datasheet)

(5) Data record statistic function:

AVG (field name) to derive a table column average
Count (*| field name) statistics on the number of data rows or the number of data rows that have a value for a column
Max (field name) gets the maximum value of a table column
Min (field name) gets the smallest value of a table column
sum (field name) adds the value of the data bar

How to reference the above function:

Sql= "selectsum (field name) as Alias from data table where condition expression"
Setrs=conn.excute (SQL)

Using RS ("Alias") to obtain the value of the unified, other functions using the same.

(5) The establishment and deletion of the data table:

CreateTable Datasheet Name (field 1 type 1 (length), Field 2 type 2 (length) ...)

Example: CREATETABLEtab01 (Namevarchar), Datetimedefaultnow ())

Droptable data table name (permanently deletes a datasheet)

Page=request.querystring ("page")

Ifpage=emptythenpage=1

Rs.Open "Select ...", conn,1,1

Rs.pagesize= per page record number

Ifnotrs.eofthenrs.absolutepage=page

Fori=1tors.pagecount

Ifi=cint (page) Then

Response.Write "<b>" &i& "</b>"

Else

Response.Write "<ahref= page. asp?page=" &i& ">" &i& "</a>"

endif

Next

Fori=1tors.pagesize

Ifnotrs.eofthen

Response.writers (0) &rs (1) ...

Rs.movenext

endif

Next

Response.Write "<ahref= page .asp?page=1> Home </a>"

Response.Write "<ahref= page. asp?page=" &page-1& "> Prev </a>"

Response.Write "<ahref= page. asp?page=" &page+1& "> Next </a>"

Response.Write "<ahref= this page. asp?page=" &rs.pagecount& "> End </a>"



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.