如何用ASP远程在数据库中创建Table (转)

本文介绍了ADO在数据库数据操作中的应用。包括向记录集添加字段、添加新记录并设置值,最后更新保存。还提及ADO的多种功能,如排序、数据流式输出、数据持久化等,展示了使用ADO进行数据操作的方法和优势。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Dim objRS
Set objRS = Server.CreateObject( "ADODB.Recordset" )
objRS.CursorLocation = adUseClient
 

objRS.Fields.Append "Product", adBSTR
objRS.Fields.Append "Quantity", adInteger
objRS.Fields.Append "Unit Price", adCurrency
 

objRS.Open
objRS.AddNew
An empty record now exists; you just need to set the values.

objRS.Fields( "Product" ).value = "1969 Camero RS"
objRS.Fields( "Quantity" ).value = 3
objRS.Fields( "Unit Price" ).value = 2000.40
And finally Update() is called to save the changes.

objRS.Update
 

ADO Added Value
If that were all, using ADO in this way would be no better than using
arrays. However, you now get to use all that great functionality
built into ADO. Let's look at some specific examples.

Methods
There are many methods available in ADO used for data manipulation. A
popular feature is sorting. Instead of writing code to sort an array
you can store the data in an ADO Recordset object and sort it.

objRS.Sort = "Product"
This creates a temporary index based on the Product field, so when
the records are accessed they will be returned in a sorted order.

Streaming
Data in a recordset can be streamed out as a string. An example of
its use is building a comma-delimited file to import into Excel. Here
is an example:

asString = objRS.GetString( adClipString, , "," )
The method GetString() starts at the current cursor position, so be
sure to call MoveFirst if you intend to stream all the records. The
parameters to GetString() allow you to control the number of rows to
convert, the column delimiter, the row delimiter and the expression
used for a NULL field.

Persistence
Persisting data to a file so that a data structure can be
reconstructed later is tedious if you are using standard data types,
since you have to create your own persistence mechanism. ADO has
persistence built in so you get it for free. To write your recordset
to a file just call Save() .

objRS.Save "theOrder.dat", adPersistADTG
The file type in this case is "Advanced Data Tablegram" format. This
is a proprietary Microsoft format, so it is only really useful for
storing a recordset in a file. The only other option is adPersistXML.

To reconstruct the recordset from the file just do the following:

Dim objRS2
Set objRS2 = Server.CreateObject( "ADODB.Recordset" )
objRS2.Open "theOrder.dat"


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-124488/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10294527/viewspace-124488/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值