在创建数据库脚本之前,必须提供一条使ADO定位、标识和与数据库通讯的途径。数据库驱动程序使用Data Source Name(DSN)定位和标识特定的ODBC兼容数据库,将信息从Web应用程序传递给数据库。典型情况下,DSN包含数据库配置、用户安全性和定位信息,且可以获取 Windows NT注册表项中或文本文件的表格。
<%
\'Create a connection object
Set cn = Server.CreateObject(\"ADODB.Connection\")
\'Open a connection; the string refers to the DSN
cn.Open \"FILEDSN=MyDatabase.dsn\"
%>
注意无论在等号(=)之前还是之后,DSN字符串都不能包含空格。
在这种情况下,Connection 对象的Open方法引用基于DSN的文件,其中包含关于数据库的位置和配置信息。也可以不引用DSN,直接显式引用供应程序、数据源、用户ID和密码。有关建立连接的可选方法的详细信息,请参阅Microsoft ActiveX Data Objects(ADO)。
<%
\'Define file based DSN
strDSN = \"FILEDSN=MyDatabase.dsn\"
\'Instantiate the Connection object and open a database connection
Set cn = Server.CreateObject(\"ADODB.Connection\")
cn.Open strDSN
\'Define SQL SELECT statement
strSQL = \"INSERT INTO Customers (FirstName, LastName) VALUES
(\'Jose\',\'Lugo\')\"
\'Use the Execute method to issue a SQL query to database
cn.Execute(strSQL)
%>
根据Recordset对象的指针类型属性设置,您可以滚动和更新记录。数据库指针可以让您在一组记录中定位到特定的项。指针还用于检索和检查记录,然后在这些记录的基础上执行操作。Recordset对象有一些属性,可用于精确地控制指针的行为,提高您检查和更新结果的能力。例如,您可以使用CursorType和CursorLocation属性设置指针的类型,将结果返回给客户端应用程序(结果通常保留在数据库服务器上)并显示其他用户对数据库的最后一次更改。有关配置Recordset对象指针的信息,请参阅Microsoft ActiveX Data Objects(ADO)。
<%
\'Establish a connection with data source
strDSN = \"FILEDSN=MyDatabase.dsn\"
Set cn = Server.CreateObject(\"ADODB.Connection\")
cn.Open strDSN
\'Instantiate a Recordset object
Set rsCustomers = Server.CreateObject(\"ADODB.Recordset\")
\'Open a recordset using the Open method
\' and use the connection established by the Connection object
strSQL = \"SELECT FirstName, LastName FROM Customers WHERE LastName =
\'Smith\' \"
rsCustomers.Open strSQL, cn
Cycle through record set and display the results
\' and increment record position with MoveNext method
Set objFirstName = rsCustomers(\"FirstName\")
Set objLastName = rsCustomers(\"LastName\")
Do Until rsCustomers.EOF
Response.Write objFirstName & \" \" & objLastName & \"<BR>\"
rsCustomers.MoveNext
Loop
%>
<%
strDSN = \"FILEDSN=MyDatabase.dsn\"
strSQL = \"SELECT FirstName, LastName FROM Customers WHERE LastName =
\'Smith\' \"
Set rsCustomers = Server.CreateObject(\"ADODB.Recordset\")
\'Open a connection using the Open method
\'and use the connection established by the Connection object
rsCustomers.Open strSQL, strDSN
\'Cycle through the record set, display the results,
\' and increment record position with MoveNext method
Set objFirstName = rsCustomers(\"FirstName\")
Set objLastName = rsCustomers(\"LastName\")
Do Until rsCustomers.EOF
Response.Write objFirstName & \" \" & objLastName & \"<BR>\"
rsCustomers.MoveNext
Loop
%>
当使用Recordset对象的Open方法建立一个连接时,必须使用Connection对象去保证链接的安全。详细信息,请参阅Microsoft ActiveX Data Objects(ADO)。
<%
\'Open a connection using Connection object Command object
\'does not have an Open method for establishing a connection
strDSN = \"FILEDSN=MyDatabase.dsn\"
Set cn = Server.CreateObject(\"ADODB.Connection\")
cn.Open strDSN
\'Instantiate Command object; use ActiveConnection property to attach
\'connection to Command object
Set cm= Server.CreateObject(\"ADODB.Command\")
Set cm.ActiveConnection = cn
\'Define SQL query
cm.CommandText = \"INSERT INTO Inventory (Material, Quantity) VALUES
(?, ?)\"
\'Save a prepared (or pre-compiled) version of the query specified in
CommandText
\'property before a Command object\'s first execution.
cm.Prepared = True
\'Define query parameter configuration information
cm.Parameters.Append cm.CreateParameter(\"material_type\",200, ,255 )
cm.Parameters.Append cm.CreateParameter(\"quantity\",200, ,255 )
\'Define and execute first insert
cm(\"material_type\") = \"light bulbs\"
cm(\"quantity\") = \"40\"
cm.Execute
\'Define and execute second insert
cm(\"material_type\") = \"fuses\"
cm(\"quantity\") = \"600\"
cm.Execute
%>
<%
\'Open a connection using Connection object. The Command object
\'does not have an Open method for establishing a connection
strDSN = \"FILEDSN=MyDatabase.dsn\"
Set cn = Server.CreateObject(\"ADODB.Connection\")
cn.Open strDSN
\'Instantiate Command object
\'and use ActiveConnection property to attach
\'connection to Command object
Set cm= Server.CreateObject(\"ADODB.Command\")
Set cm.ActiveConnection = cn
\'Define SQL query
cm.CommandText = \"INSERT INTO MySeedsTable (Type) VALUES (?)\"
\'Define query parameter configuration information
cm.Parameters.Append cm.CreateParameter(\"type\",200, ,255 )
\'Define and execute insert
cm(\"type\") = Request(\"SeedType\")
cm.Execute
%>
在创建数据库脚本之前,必须提供一条使ADO定位、标识和与数据库通讯的途径。数据库驱动程序使用Data Source Name(DSN)定位和标识特定的ODBC兼容数据库,将信息从Web应用程序传递给数据库。典型情况下,DSN包含数据库配置、用户安全性和定位信息,且可以获取 Windows NT注册表项中或文本文件的表格。
<%
\'Create a connection object
Set cn = Server.CreateObject(\"ADODB.Connection\")
\'Open a connection; the string refers to the DSN
cn.Open \"FILEDSN=MyDatabase.dsn\"
%>
注意无论在等号(=)之前还是之后,DSN字符串都不能包含空格。
在这种情况下,Connection 对象的Open方法引用基于DSN的文件,其中包含关于数据库的位置和配置信息。也可以不引用DSN,直接显式引用供应程序、数据源、用户ID和密码。有关建立连接的可选方法的详细信息,请参阅Microsoft ActiveX Data Objects(ADO)。
<%
\'Define file based DSN
strDSN = \"FILEDSN=MyDatabase.dsn\"
\'Instantiate the Connection object and open a database connection
Set cn = Server.CreateObject(\"ADODB.Connection\")
cn.Open strDSN
\'Define SQL SELECT statement
strSQL = \"INSERT INTO Customers (FirstName, LastName) VALUES
(\'Jose\',\'Lugo\')\"
\'Use the Execute method to issue a SQL query to database
cn.Execute(strSQL)
%>
根据Recordset对象的指针类型属性设置,您可以滚动和更新记录。数据库指针可以让您在一组记录中定位到特定的项。指针还用于检索和检查记录,然后在这些记录的基础上执行操作。Recordset对象有一些属性,可用于精确地控制指针的行为,提高您检查和更新结果的能力。例如,您可以使用CursorType和CursorLocation属性设置指针的类型,将结果返回给客户端应用程序(结果通常保留在数据库服务器上)并显示其他用户对数据库的最后一次更改。有关配置Recordset对象指针的信息,请参阅Microsoft ActiveX Data Objects(ADO)。
<%
\'Establish a connection with data source
strDSN = \"FILEDSN=MyDatabase.dsn\"
Set cn = Server.CreateObject(\"ADODB.Connection\")
cn.Open strDSN
\'Instantiate a Recordset object
Set rsCustomers = Server.CreateObject(\"ADODB.Recordset\")
\'Open a recordset using the Open method
\' and use the connection established by the Connection object
strSQL = \"SELECT FirstName, LastName FROM Customers WHERE LastName =
\'Smith\' \"
rsCustomers.Open strSQL, cn
Cycle through record set and display the results
\' and increment record position with MoveNext method
Set objFirstName = rsCustomers(\"FirstName\")
Set objLastName = rsCustomers(\"LastName\")
Do Until rsCustomers.EOF
Response.Write objFirstName & \" \" & objLastName & \"<BR>\"
rsCustomers.MoveNext
Loop
%>
<%
strDSN = \"FILEDSN=MyDatabase.dsn\"
strSQL = \"SELECT FirstName, LastName FROM Customers WHERE LastName =
\'Smith\' \"
Set rsCustomers = Server.CreateObject(\"ADODB.Recordset\")
\'Open a connection using the Open method
\'and use the connection established by the Connection object
rsCustomers.Open strSQL, strDSN
\'Cycle through the record set, display the results,
\' and increment record position with MoveNext method
Set objFirstName = rsCustomers(\"FirstName\")
Set objLastName = rsCustomers(\"LastName\")
Do Until rsCustomers.EOF
Response.Write objFirstName & \" \" & objLastName & \"<BR>\"
rsCustomers.MoveNext
Loop
%>
当使用Recordset对象的Open方法建立一个连接时,必须使用Connection对象去保证链接的安全。详细信息,请参阅Microsoft ActiveX Data Objects(ADO)。
<%
\'Open a connection using Connection object Command object
\'does not have an Open method for establishing a connection
strDSN = \"FILEDSN=MyDatabase.dsn\"
Set cn = Server.CreateObject(\"ADODB.Connection\")
cn.Open strDSN
\'Instantiate Command object; use ActiveConnection property to attach
\'connection to Command object
Set cm= Server.CreateObject(\"ADODB.Command\")
Set cm.ActiveConnection = cn
\'Define SQL query
cm.CommandText = \"INSERT INTO Inventory (Material, Quantity) VALUES
(?, ?)\"
\'Save a prepared (or pre-compiled) version of the query specified in
CommandText
\'property before a Command object\'s first execution.
cm.Prepared = True
\'Define query parameter configuration information
cm.Parameters.Append cm.CreateParameter(\"material_type\",200, ,255 )
cm.Parameters.Append cm.CreateParameter(\"quantity\",200, ,255 )
\'Define and execute first insert
cm(\"material_type\") = \"light bulbs\"
cm(\"quantity\") = \"40\"
cm.Execute
\'Define and execute second insert
cm(\"material_type\") = \"fuses\"
cm(\"quantity\") = \"600\"
cm.Execute
%>
<%
\'Open a connection using Connection object. The Command object
\'does not have an Open method for establishing a connection
strDSN = \"FILEDSN=MyDatabase.dsn\"
Set cn = Server.CreateObject(\"ADODB.Connection\")
cn.Open strDSN
\'Instantiate Command object
\'and use ActiveConnection property to attach
\'connection to Command object
Set cm= Server.CreateObject(\"ADODB.Command\")
Set cm.ActiveConnection = cn
\'Define SQL query
cm.CommandText = \"INSERT INTO MySeedsTable (Type) VALUES (?)\"
\'Define query parameter configuration information
cm.Parameters.Append cm.CreateParameter(\"type\",200, ,255 )
\'Define and execute insert
cm(\"type\") = Request(\"SeedType\")
cm.Execute
%>
在创建数据库脚本之前,必须提供一条使ADO定位、标识和与数据库通讯的途径。数据库驱动程序使用Data Source Name(DSN)定位和标识特定的ODBC兼容数据库,将信息从Web应用程序传递给数据库。典型情况下,DSN包含数据库配置、用户安全性和定位信息,且可以获取 Windows NT注册表项中或文本文件的表格。
<%
\'Create a connection object
Set cn = Server.CreateObject(\"ADODB.Connection\")
\'Open a connection; the string refers to the DSN
cn.Open \"FILEDSN=MyDatabase.dsn\"
%>
注意无论在等号(=)之前还是之后,DSN字符串都不能包含空格。
在这种情况下,Connection 对象的Open方法引用基于DSN的文件,其中包含关于数据库的位置和配置信息。也可以不引用DSN,直接显式引用供应程序、数据源、用户ID和密码。有关建立连接的可选方法的详细信息,请参阅Microsoft ActiveX Data Objects(ADO)。
<%
\'Define file based DSN
strDSN = \"FILEDSN=MyDatabase.dsn\"
\'Instantiate the Connection object and open a database connection
Set cn = Server.CreateObject(\"ADODB.Connection\")
cn.Open strDSN
\'Define SQL SELECT statement
strSQL = \"INSERT INTO Customers (FirstName, LastName) VALUES
(\'Jose\',\'Lugo\')\"
\'Use the Execute method to issue a SQL query to database
cn.Execute(strSQL)
%>
根据Recordset对象的指针类型属性设置,您可以滚动和更新记录。数据库指针可以让您在一组记录中定位到特定的项。指针还用于检索和检查记录,然后在这些记录的基础上执行操作。Recordset对象有一些属性,可用于精确地控制指针的行为,提高您检查和更新结果的能力。例如,您可以使用CursorType和CursorLocation属性设置指针的类型,将结果返回给客户端应用程序(结果通常保留在数据库服务器上)并显示其他用户对数据库的最后一次更改。有关配置Recordset对象指针的信息,请参阅Microsoft ActiveX Data Objects(ADO)。
<%
\'Establish a connection with data source
strDSN = \"FILEDSN=MyDatabase.dsn\"
Set cn = Server.CreateObject(\"ADODB.Connection\")
cn.Open strDSN
\'Instantiate a Recordset object
Set rsCustomers = Server.CreateObject(\"ADODB.Recordset\")
\'Open a recordset using the Open method
\' and use the connection established by the Connection object
strSQL = \"SELECT FirstName, LastName FROM Customers WHERE LastName =
\'Smith\' \"
rsCustomers.Open strSQL, cn
Cycle through record set and display the results
\' and increment record position with MoveNext method
Set objFirstName = rsCustomers(\"FirstName\")
Set objLastName = rsCustomers(\"LastName\")
Do Until rsCustomers.EOF
Response.Write objFirstName & \" \" & objLastName & \"<BR>\"
rsCustomers.MoveNext
Loop
%>
<%
strDSN = \"FILEDSN=MyDatabase.dsn\"
strSQL = \"SELECT FirstName, LastName FROM Customers WHERE LastName =
\'Smith\' \"
Set rsCustomers = Server.CreateObject(\"ADODB.Recordset\")
\'Open a connection using the Open method
\'and use the connection established by the Connection object
rsCustomers.Open strSQL, strDSN
\'Cycle through the record set, display the results,
\' and increment record position with MoveNext method
Set objFirstName = rsCustomers(\"FirstName\")
Set objLastName = rsCustomers(\"LastName\")
Do Until rsCustomers.EOF
Response.Write objFirstName & \" \" & objLastName & \"<BR>\"
rsCustomers.MoveNext
Loop
%>
当使用Recordset对象的Open方法建立一个连接时,必须使用Connection对象去保证链接的安全。详细信息,请参阅Microsoft ActiveX Data Objects(ADO)。
<%
\'Open a connection using Connection object Command object
\'does not have an Open method for establishing a connection
strDSN = \"FILEDSN=MyDatabase.dsn\"
Set cn = Server.CreateObject(\"ADODB.Connection\")
cn.Open strDSN
\'Instantiate Command object; use ActiveConnection property to attach
\'connection to Command object
Set cm= Server.CreateObject(\"ADODB.Command\")
Set cm.ActiveConnection = cn
\'Define SQL query
cm.CommandText = \"INSERT INTO Inventory (Material, Quantity) VALUES
(?, ?)\"
\'Save a prepared (or pre-compiled) version of the query specified in
CommandText
\'property before a Command object\'s first execution.
cm.Prepared = True
\'Define query parameter configuration information
cm.Parameters.Append cm.CreateParameter(\"material_type\",200, ,255 )
cm.Parameters.Append cm.CreateParameter(\"quantity\",200, ,255 )
\'Define and execute first insert
cm(\"material_type\") = \"light bulbs\"
cm(\"quantity\") = \"40\"
cm.Execute
\'Define and execute second insert
cm(\"material_type\") = \"fuses\"
cm(\"quantity\") = \"600\"
cm.Execute
%>
<%
\'Open a connection using Connection object. The Command object
\'does not have an Open method for establishing a connection
strDSN = \"FILEDSN=MyDatabase.dsn\"
Set cn = Server.CreateObject(\"ADODB.Connection\")
cn.Open strDSN
\'Instantiate Command object
\'and use ActiveConnection property to attach
\'connection to Command object
Set cm= Server.CreateObject(\"ADODB.Command\")
Set cm.ActiveConnection = cn
\'Define SQL query
cm.CommandText = \"INSERT INTO MySeedsTable (Type) VALUES (?)\"
\'Define query parameter configuration information
cm.Parameters.Append cm.CreateParameter(\"type\",200, ,255 )
\'Define and execute insert
cm(\"type\") = Request(\"SeedType\")
cm.Execute
%>