1. Construct a database in SQL Server Name: House run the following script in House
IF exists (Select * from sysobjects where id = Object_id (n '[dbo]. [city]') And ObjectProperty (ID, n'susertable ') = 1)
Drop Table [dbo]. [City]
Go
IF exists (select * from sysobjects where id = Object_id (n '[dbo]. [area]') And ObjectProperty (id, n'uSERTABLE ') = 1)
DROP TABLE [DBO]. [Area]
Go
Create Table [DBO]. [City] (
[ID] [INT] Identity (1, 1) Not NULL,
[Name] [NVARCHAR] (10) NULL
) On [primary]
Go
Create Table [DBO]. [Area] (
[ID] [INT] Identity (1, 1) Not NULL,
[City] [int] null,
[Name] [NVARCHAR] (20) NULL
) On [primary]
Go
INSERT INTO City (ID, Name) Values (1, "Guangzhou")
INSERT INTO City (ID, Name) Values (2, "Shanghai")
INSERT INTO City (ID, Name) Values (3, "Beijing")
INSERT INTO Area (ID, CityID, Name) Values (1, 1, "Tianhe")
INSERT INTO Area (ID, CityID, Name) Values (2, 1, "Baiyun")
INSERT INTO Area (ID, CityID, Name) Values (3, 2, "Hongkou")
Insert Into Area (ID, CityID, Name) Values (4, 2, "Baoshan")
INSERT INTO Area (ID, CityID, Name) Values (5, 2, "Jing'an")
INSERT INTO Area (ID, CityID, Name) Values (6, 3, "Haidian")
INSERT INTO Area (ID, CityID, Name) Values (7, 3, "Chaoyang")
2. Create a file
Create files for CITYDATA.ASP
<% @ Language = VBScript%>
<% Rsdispatch%>
Function description ()
{
THIS.GETAREAASARRAY = DOGETDATA;
}
Public_description = new description ();
Function DogetData (CityID)
{
Var SQL, RST, STRTEXT, CONN, I, J
CONN = New ActiveXObject ("AdoDb.Connection");
Conn.connectionstring = conn.connectionTIMEOUT = 30;
Cn.open ();
SQL = "SELECT NAME, ID from area where cityid = '" cityid "'"
RST = New ActiveXObject ("AdoDb.Recordset");
Rst.cursorLocation = 3;
Rst.Open (SQL, CONN);
i = 0;
J = 0;
strText = new array ();
IF (Rst.Recordcount> = 1)
{
For (VAR i = 0; i { Strtext [J ] = Rst.fields ("Name"). Value; Strtext [J ] = RST.Fields ("ID"). Value; Rst.movenext (); } } Else { Strtext [J ] = "No"; STRTEXT [J ] = 1; } Rst.close (); CONN.CLOSE (); Return strText; } Script> Create file jsconn.asp Var connStr = "driver = {SQL Server}; server = 202.0.0.108; uid = sa; pwd =; database = house"; Script> Establish file Pub.asp <% Function Openorget_DATABASE DIM sessionname, conn Const connStr = "driver = {SQL Server}; server = 202.0.0.108; uid = sa; pwd =; database = house" Sessionname = "house" If not isobject (session (sessionname) THEN Set conn = server.createObject ("adoDb.connection") Conn.open connStr Set session (sessionname) = conn END IF Set Openorget_Database = session (sessionname) END FUNCTION %> Establish file SQL_PUB.ASP <% 'Remove the city information Function selectcity () DIM CONN, SQL, RS, Arrcity, TMPARR (1, 0) SET CONN = Openorget_Database SET RS = Server.createObject ("AdoDb.Recordset") SQL = "SELECT DISTINCT NAME, ID from City" RS.Open SQL, CONN, 3 IF r.eof then TMPARR (0, 0) = "City" TMPARR (1,0) = 0rs.close SelectCity = TMPARR Else Arrcity = rs.getrows () Rs.close SELECTCITY = Arrcity END IF END FUNCTION 'Remove the corresponding regional information based on the promising CITYID Function SelectArea (CityID) DIM CONN, SQL, RS, Arrarea, TMPARR (1, 0) SET CONN = Openorget_Database SET RS = Server.createObject ("AdoDb.Recordset") SQL = "SELECT NAME, ID from area where cityid =" & cityid & "order by id" RS.Open SQL, CONN, 3 IF r.eof then TMPARR (0, 0) = "Region" TMPARR (1,0) = 0 Rs.close SELECTAREA = TMPARR Else Arrarea = rs.getrows () Rs.close Selectarea = Arrarea END IF END FUNCTION %> Create file test.asp <% @ Language = "VBScript"%> <% OPTION Explicit%> <% DIM Arrcity, Arrarea, StrPathinfo, STRSERVERNAME, STRSERVERPORT, I, TMPSTR StrPathInfo = Request.ServerVariables ("Path_INFO") STRSERVERNAME = Request.SerVariables ("Server_Name") STRSERVERPORT = Request.SerVariables ("Server_Port") if Len (STRSERVERPORT) = 0 THEN strServerport = "" Else STRSERVERPORT = ":" STRSERVERPORT END IF StrPathInfo = "http: //" & strservername & strserverport & "" Arrcity = SELECTCITY () Arrarea = SELECTAREA (Arrcity (1,0)) %>
hEAD>