ASP and Access database

xiaoxiao2021-03-06  46

1 Customize a table to make it uploaded from the database:

<% Set = server.createObject ("adoDb.recordset")

Rs.open "SELECT * from AD ORDER BY BS", CONN, 1, 1

Do While Not Rs.eof

Response.write "
"

rs.movenext

loop

Rs.close

SET RS = Nothing

%>

Note: "WordLink" is a field name inside.

2 Connecting the database generally use this statement:

The conn.asp code is as follows:

<% @ Codepage = "936"%> // This sentence can be done

<%

DIM Conn

DIM ConnStr

DIM DB

DB = "db / my.mdb"

Set conn = server.createObject ("adoDb.connection")

Connstr = "provider = microsoft.jet.Oledb.4.0; data source =" & server.mappath (db)

Conn.open connStr

Startime = Timer ()

%>

3 For example: The page adds a message is added: (subsequent file name is tianjia.asp)

<%

SET RS = Server.createObject ("AdoDb.Recordset")

Name = Request ("name")

Mail = Request ("email")

Face = Request ("face")

SQL = "SELECT * from Message" (Message is a table name)

RS.Open SQL, CONN, 3, 3

rs.addnew

RS ("a_name") = name

RS ("a_mail") = mail

RS ("Face" = Face // This is the selected image, you can use image / 1.jpg in the field of the database table.

Rs.Update

Rs.close

Response.Redirect "xianshi.asp" // This sentence is a redirected page, that is, jump to xianshi.asp

%>

<%

SET RS = Nothing

Conn.close

Set conn = Nothing

%>

When you write this statement:

When submitting Tianjia.asp

4 <%

SET RS = Server.createObject ("AdoDb.Recordset" // To operate the table, you can do this. Sqlcmd = "select * from message order by a_time desc" // Sort by time (A_TIME) is a field

Rs.Open Sqlcmd, Conn, AdopenStatic, AdlockPESSIMISTIC

Page = clng (Request ("txtpage")))

Rs.pageSize = 5 // Display five information per page

IF page <1 THEN PAGE = 1

IF page> rs.pagecount then page = rs.pagecount // Total number

Rs.absolutepage = Page

%>

● Use only this statement when you want to display the total number of pages: <% = rs.pagecount%>

● To display the current page as the first few pages as long as this statement: <% = Page%>

● Below is the implementation of the previous page, the next page

<%

IF Page <> 1 THEN

Response.write " " & _

""

Response.write " " & _

" Previous page "

END IF

IF Page <> rs.pagecount then

Response.write " " & _

" Next page

Response.write " " & _

""

END IF%>

From Guangdong

Image

|

|

|

|

| Image

first name

From <% = rs ("Area")%> to call out "Guangdong" "" "" "" "" ""%> "width =" "90" Height = "90" Border = 0> Toned the picture The same below is also the <% = RS ("A_NAME")% that is called from the database, what is required to drop the light Where is the "Number" finally don't need to turn off the table and the database to the data table. The code is as follows: As long as the table does not turn off, the database can be operated at any time, that is, the following statement <% = RS ("Face")%> is taken.

<%

Rs.movenextif rs.eof kil1en exit for

NEXT

Rs.close

Conn.close

%>


New Post(0)