【vfp开源代码栏目提醒】:本文主要为网学会员提供adocursoradapter0.prg,希望对需要adocursoradapter0.prg网友有所帮助,学习一下!
LOCAL oConn AS ADODB.Connection,cStrung AS Character,oRs AS ADODB.RecordSet,oCmd AS ADODB.Command,aErrors[1]
cString="Provider=SQLOLEDB.1;Data Source=ccb-zhj;Initial Catalog=Northwind;UID=sa;PWD=;Trusted_Connection=NO"
oConn=CREATEOBJECT("ADODB.Connection") &&建立连接对象
oConn.Open(cString) &&打开连接
oRs=CREATEOBJECT("ADODB.RecordSet")
oRS.CursorType=3 &&静态游标
oRS.LockType=3 &&乐观锁定
oCmd=CREATEOBJECT("ADODB.Command")
oCmd.ActiveConnection=oConn &&注意必须设置此属性
oCursor=CREATEOBJECT("CursorAdapter")
WITH oCursor
.AllowDelete=.T.
.AllowInsert=.T.
.AllowUpdate=.T.
.Alias="curCustomers" &&本地临时表名称
.ConflictCheckType=3 &&检测更新冲突
.DataSourceType="ADO"
.DataSource=oRs &&数据源为RecordSet对象
.KeyFieldList="CustomerID"
.UpdatableFieldList="CompanyName,ContactName,Country"
.UpdateNameList="CustomerID Customers.CustomerID,CompanyName Customers.CompanyName,"+;
"Country Customers.Country"
.SelectCmd="SELECT CustomerID,CompanyName,ContactName,Country FROM Customers WHERE Country=?lcVar"
.SendUpdates=.T.
.Tables="Customers"
ENDWITH
lcVar="Brazil"
IF oCursor.CursorFill(.F., .F., 0,oCmd) &&必须将Command对象作为CursorFill方法的第4个参数
BROWSE
?TABLEUPDATE(.T.)
ELSE
=AERROR(aErrors)
=MESSAGEBOX(aErrors[2])
ENDIF