贵州蜡染市场销售:介绍asp 中数据库连接的英文资料

来源:百度文库 编辑:神马品牌网 时间:2024/05/02 19:04:37
我需要一篇介绍有关asp中ado数据库连接的英文资料,望各为兄弟姐妹帮帮忙!谢谢!

Database Connectivity with ASP and ADO

ASP uses a technology called ActiveX Data Objects (ADO) to work with databases. ADO is ActiveX technology which is built into the Internet Information Server (IIS). It is comprised of a number of objects which you can use. I will begin by explaining the "major players" briefly.

There are 3 major objects which you should be aware of in ADO: the Command Object, the Connection Object, and the Recordset object. Most of the time, you will only have to work with the RecordSet object (arguably), but in certain cases, you may want to set properties in (or use) one or both of the other 2 objects. Whenever you perform a database operation, these 3 objects are present, but it isn't necessary often to explicitly create all 3, as when one is used, the other 2 are implicitly created, even though you may not assign a variable to access them. The syntax for creating a variable to access these objects is (in VBScript) "[variable name] = Server.CreateObject("ADODB.[object name]")"

The RecordSet Object

The RecordSet object is basically a cursor (a temporary table which exists in memory) with some built-in functions and properties for working with the records contained in it. You can create a RecordSet object explicitly, or by executing a command through the Command Object.

Some of the properties which you may use frequently are:

BOF - Beginning of file

EOF - End of file

MaxRecords - Maximum number of records returned in a query

RecordCount - The number of records in the RecordSet

CursorType - Forward-only, static,dynamic, and keyset

Some of the methods (functions) of the RecordSet object which you may be most likely to use are:

Open - Open the Recordset

Close - Close the RecordSet

Move - Move to a specific record

MoveFirst - Move to the first record

MoveNext - Move forward one record

Move Previous - Move backwards one record

MoveLast - Move to the last record

AddNew - Add a new record to the RecordSet

Update - Update the current record

The Command Object

The Command Object is the workhorse of ADO. It is the object which commands the database, whether it's issuing an SQL statement, or executing a stored procedure contained in the database itself. using the Command Object, you can create parameterized queries, which can be altered on the fly. You can change the query being issued, and change the properties of the Command Object itself.

There are far less properties of a Command Object than a Recordset object. In fact, you're only likely to use the following , if any:

CommandText - The actual text of the command, such as a SQL statement

ActiveConnection - The associated Connection Object.

There are only 2 methods for a Command Object. They are:

CreateParameter - Create a parameter for a query in the Parameters Collection

Execute - Execute the Command

The Command Object also has a collection called the Parameters Collection. This is where parameters are organized for parameterized queries. Parameters have properties as well, and can be accessed either by their position in the Parameters Collection (index), or by name.

You can use parameters in your SQL statements by inserting question marks for each parameter used. The parameters must first be defined, and their values will be substituted in the query in the order they appear in the collection. If you wish to use parameterized queries, you might want to read up some more on this subject, but I don't want to take all day.

The Connection Object

The Connection Object is the object which actually does the "talking" with the database. It defines the connection type, and properties too numerous to mention. It may contain a System DSN name which is used to identify the ODBC driver and path to the database. I may contain the physical path to the database. It can also store user name and password information which is used to gain access to a secure database. And it can fine-tune the connection in other ways as well. The Command Object and RecordSet object actually access the database through the Connection Object. However, it isn't often necessary to use this object, as it can be implicitly created by the RecordSet Object (my favorite method), and the default values for the many properties are usually fine to work with.

The single most important and most-often used property of the Connection Object is the ConnectionString property. If you have used IDC (Internet Database Connector) before, you're familiar with identifying the System DSN. This is handled in the ConnectionString Property, as well as some other properties as well. The ConnectionString property is defined by a string of property definitions (name/value pairs) separated by semicolons. Here is an example:

"DSN=jobs;DBQ=C:\AOL30A\download\San Diego Jobs\jobs.mdb;DriverId=25;FIL=MS Access;MaxBufferSize=512;PageTimeout=5;"

You'll notice that the System DSN is the first item identified, followed by the "DBQ" (the physical location of the database). Other properties are defined as well. This Connection String was "borrowed" from a global.asa file created automatically by Microsoft Visual InterDev. However, you'll find that in the vast majority of cases, it isn't necessary to define all of these (and/or more) properties of the Connection object.

In fact, I'm going to show you a simple way to use ADO to do most of your routine database stuff, and you can forget most of what you've read here (unless you need to do something fancy). The following is a demonstration of some simple VBScript to execute a SELECT statement. You can even copy and paste this into your own ASP pages if you wish.

We'll begin with the assumption that the user has filled out a form containing a single field called "lastname." They are looking up personnel records in a table called "personnel," and want to find all records with a "lastname" field containing the name they've typed in in the form. A System DSN has been set up using the 32-Bit ODBC Driver Administrator, by the name of "mydsn." If you've read my earlier articles about ASP, you remember that to obtain the value of a form field, you use the ASP Request.Form Object, and name the field. So, without any further ado, let us proceed with the code:

A Simple ASP ADO SQL Query

Set rs = Server.CreateObject("ADODB.RecordSet")
param = Request.Form("lastname")
q = "SELECT * FROM personnel WHERE lastname LIKE '" & param & "'"
rs.Open q, "DSN=mydsn;"

if NOT rs.EOF then
while NOT rs.EOF
Response.Write rs("firstname") & " " & rs("lastname") & "<BR>"
rs.MoveNext
wend
end if

A Simple Explanation of A Simple ASP ADO SQL Query

Line 1. Create Recordset object
Line 2. Place form field value in a variable named "param"
Line 3. Define query by concatenating strings and variable value
Line 4. Open RecordSet Object. Note that the first parameter is the Command Text. The second parameter is the Connection String. The Command Object and Connection Object are created implicitly.
Line 5. Make sure the RecordSet isn't empty
Line 6. Begin executing a loop which goes through all records in the RecordSet.
Line 7. Write each record's "firstname" and "lastname" fields to the page on a separate line.
Line 8. Move to Next Record.

英文没有学好
郁闷

动态数据库连接及与红 采用数据储存技术要求启动Objects(ADO)与数据库. 这是简单的技术纳入启动因特网信息服务器(IIS). 它是由许多东西可以利用. 我将首先解释"主要角色"简单. 有3大目标,你应该知道,阿:司令部对象,对象方面,recordset对象. 很多时候,你只能与recordset对象(可能),但在某些情况下,你要确定物业(或使用)一方或双方的其他物品2. 当你的数据库进行操作,这些物品都是3本,但没有必要明确往往造成3所有,当一个人用,另外2个间接造成,即使你不把进入一个变数. 句法为创造一个变数的使用对象是(VBScript)"变名]=Server.CreateObject("ADODB. [对象名称]")" 在Recordset对象 recordset的目标基本上是激活(临时表,存在于记忆)有固定的工作职能和财产的记录中. 你可以创造一个recordset对象明确,即通过指挥部指挥执行的对象. 一些你可以使用的特性,经常是: BOF,开始档案 EOF式档案 Maxrecords,最多时有记录返回 RecordCount-在Recordset的记录 Cursortype-前瞻只有静态、动态、keyset 有些方法(功能)的对象recordset你可以用最有可能是: 开放打开Recordset 接近结束Recordset 迁入具体举措纪录 MoveFirst--记走向 MoveNext--前进一纪录 以前提出的一项纪录后退 moveLast--走向最后纪录 Addnew-增添新的Recordset记录 更新-更新现有记录 指挥目标 指挥的目的是5:1版. 它的宗旨是为大众所数据库,无论是机发出声明,或者执行程序存储在数据库本身中. 利用指挥对象,可以创造parameterized问题,就可以改变飞行. 你可以改变发出质疑,并指挥改变物体本身的特性. 有少财产指挥recordset对象不是物体. 事实上,你只可能用以下任何: CommandText的实际案文指挥,如语言说明 Activeconnection-联系方面反对. 只有两个方法的指挥对象. 他们是: CreateParameter的参数建立一个收集质疑的参数 执行,执行指挥部 指挥对象也称为集收集参数. 这是参数举办parameterized疑问. 参数及特性,可通过其位置参数的收集(指数),或名称. 你可以使用参数SQL插入声明每个参数用问号. 参数必须先定义,其价值将取代在出现问题的先后顺序收集. 如果你想利用parameterized问题,你不妨多读一些有关这个问题,但我不想再整天. 连接对象 这方面的目标是根本目标"说话"的数据库. 它规定了种类方面,物业不胜枚举. 它可能包含系统所使用的名称DSNODBC找出路的司机和数据库. 我的身体上可能含有的数据库. 用户还可以存储信息,使用的名称和密码进入数据库安全. 可以微调的方式和其他方面. 指挥目标与recordset对象的数据库,通过联系实际接触物体. 但是,这不是经常需要使用这种对象,因为它可以间接造成Recordset对象(我最喜欢的方式),设定值许多优良特性通常与. 最重要和最常用的联系对象是财产ConnectionString财产. 如果您使用国际数据公司(因特网数据库连接)之前,你熟悉DSN鉴定制度. 这是在ConnectionString处理财产,以及其他一些财产. ConnectionString的财产是指财产的一系列定义(名字/值对)隔着semicolons. 这里是一个例子: "DSN=就业; DBQ=C:\Aol30a\下载\SanDiego工作\JOBS.MDB; driverid=25; fil=余准入; maxbuffersize=512; pagetimeout=5; " 你看到的是系统的第一个项目确定DSN,然后"DBQ"(数据库的实际位置). 及其他财产的定义. 这一方面是串"借用"Global.asa从微软视觉Interdev档案自动产生. 然而,你会发现在绝大多数情况下,没有必要去确定所有这些(和/或更多)对象的财产关系. 其实,我要告诉大家一个简单的方法是使用最简单,你经常数据库东西,也不会忘记你的大部份,你看这里(如果你需要做漂亮). 以下是一些简单的VBScript演示说明专责执行. 你甚至可以拷贝和浆糊自己的联系点后,如果你愿意页. 我们会首先假设用户已经填写表格含有单一领域称为"LastName. " 研究人员记录了他们的表称为"人才",要找出所有记录"lastname"野战载她们的名字,打印的方式. 已经成立了系统DSN使用32位ODBC管理司机,以"Mydsn" 如果你看过我以前文章联系,记得索取表格方面的价值,你用request.form联系对象,名称方面. 所以不要再简单,让美国进行代号: 一个简单的语言学校乐队质疑 定卢比=Server.CreateObject("ADODB.RECORDSET") 处罚=request.form("LASTNAME") Q="选拔人才,从lastname*喜欢'"&&处罚"" Rs.open问:"MYDSNDSN="; 如果不是那么rs.eof 虽不Rs.eof Response.Write卢比("FIRSTNAME")&""&卢比("LASTNAME")和"<br>" Rs.movenext Wend 如果年底 简单说明简单语言学校乐队质疑 路线1. 建立recordset对象 二号线. 地方形成了不同领域的价值被称为"处罚" 三线. 明确提出了不同的价值和条件concatenating 行. recordset对象不限. 看到的第一个参数是文本指挥. 第二个因素是有关串. 指挥方面的目标和宗旨是建立含蓄. 五线. recordset不是空洞的保证 第六. 经过一个循环,开始执行的所有记录recordset. 七线. 每写纪录"firstName"和"LastName"的网页在不同领域的路线. 八线. 明年搬到纪录.

动态数据库连接及与红 采用数据储存技术要求启动Objects(ADO)与数据库. 这是简单的技术纳入启动因特网信息服务器(IIS). 它是由许多东西可以利用. 我将首先解释"主要角色"简单. 有3大目标,你应该知道,阿:司令部对象,对象方面,recordset对象. 很多时候,你只能与recordset对象(可能),但在某些情况下,你要确定物业(或使用)一方或双方的其他物品2. 当你的数据库进行操作,这些物品都是3本,但没有必要明确往往造成3所有,当一个人用,另外2个间接造成,即使你不把进入一个变数. 句法为创造一个变数的使用对象是(VBScript)"变名]=Server.CreateObject("ADODB. [对象名称]")" 在Recordset对象 recordset的目标基本上是激活(临时表,存在于记忆)有固定的工作职能和财产的记录中. 你可以创造一个recordset对象明确,即通过指挥部指挥执行的对象. 一些你可以使用的特性,经常是: BOF,开始档案 EOF式档案 Maxrecords,最多时有记录返回 RecordCount-在Recordset的记录 Cursortype-前瞻只有静态、动态、keyset 有些方法(功能)的对象recordset你可以用最有可能是: 开放打开Recordset 接近结束Recordset 迁入具体举措纪录 MoveFirst--记走向 MoveNext--前进一纪录 以前提出的一项纪录后退 moveLast--走向最后纪录 Addnew-增添新的Recordset记录 更新-更新现有记录 指挥目标 指挥的目的是5:1版. 它的宗旨是为大众所数据库,无论是机发出声明,或者执行程序存储在数据库本身中. 利用指挥对象,可以创造parameterized问题,就可以改变飞行. 你可以改变发出质疑,并指挥改变物体本身的特性. 有少财产指挥recordset对象不是物体. 事实上,你只可能用以下任何: CommandText的实际案文指挥,如语言说明 Activeconnection-联系方面反对. 只有两个方法的指挥对象. 他们是: CreateParameter的参数建立一个收集质疑的参数 执行,执行指挥部 指挥对象也称为集收集参数. 这是参数举办parameterized疑问. 参数及特性,可通过其位置参数的收集(指数),或名称. 你可以使用参数SQL插入声明每个参数用问号. 参数必须先定义,其价值将取代在出现问题的先后顺序收集. 如果你想利用parameterized问题,你不妨多读一些有关这个问题,但我不想再整天. 连接对象 这方面的目标是根本目标"说话"的数据库. 它规定了种类方面,物业不胜枚举. 它可能包含系统所使用的名称DSNODBC找出路的司机和数据库. 我的身体上可能含有的数据库. 用户还可以存储信息,使用的名称和密码进入数据库安全. 可以微调的方式和其他方面. 指挥目标与recordset对象的数据库,通过联系实际接触物体. 但是,这不是经常需要使用这种对象,因为它可以间接造成Recordset对象(我最喜欢的方式),设定值许多优良特性通常与. 最重要和最常用的联系对象是财产ConnectionString财产. 如果您使用国际数据公司(因特网数据库连接)之前,你熟悉DSN鉴定制度. 这是在ConnectionString处理财产,以及其他一些财产. ConnectionString的财产是指财产的一系列定义(名字/值对)隔着semicolons. 这里是一个例子: "DSN=就业; DBQ=C:\Aol30a\下载\SanDiego工作\JOBS.MDB; driverid=25; fil=余准入; maxbuffersize=512; pagetimeout=5; " 你看到的是系统的第一个项目确定DSN,然后"DBQ"(数据库的实际位置). 及其他财产的定义. 这一方面是串"借用"Global.asa从微软视觉Interdev档案自动产生. 然而,你会发现在绝大多数情况下,没有必要去确定所有这些(和/或更多)对象的财产关系. 其实,我要告诉大家一个简单的方法是使用最简单,你经常数据库东西,也不会忘记你的大部份,你看这里(如果你需要做漂亮). 以下是一些简单的VBScript演示说明专责执行. 你甚至可以拷贝和浆糊自己的联系点后,如果你愿意页. 我们会首先假设用户已经填写表格含有单一领域称为"LastName. " 研究人员记录了他们的表称为"人才",要找出所有记录"lastname"野战载她们的名字,打印的方式. 已经成立了系统DSN使用32位ODBC管理司机,以"Mydsn" 如果你看过我以前文章联系,记得索取表格方面的价值,你用request.form联系对象,名称方面. 所以不要再简单,让美国进行代号: 一个简单的语言学校乐队质疑 定卢比=Server.CreateObject("ADODB.RECORDSET") 处罚=request.form("LASTNAME") Q="选拔人才,从lastname*喜欢'"&&处罚"" Rs.open问:"MYDSNDSN="; 如果不是那么rs.eof 虽不Rs.eof Response.Write卢比("FIRSTNAME")&""&卢比("LASTNAME")和"<br>" Rs.movenext Wend 如果年底 简单说明简单语言学校乐队质疑 路线1. 建立recordset对象 二号线. 地方形成了不同领域的价值被称为"处罚" 三线. 明确提出了不同的价值和条件concatenating 行. recordset对象不限. 看到的第一个参数是文本指挥. 第二个因素是有关串. 指挥方面的目标和宗旨是建立含蓄. 五线. recordset不是空洞的保证 第六. 经过一个循环,开始执行的所有记录recordset. 七线. 每写纪录"firstName"和"LastName"的网页在不同领域的路线. 八线. 明年搬到纪录.