vfp关于视图问题
一、vfp中能不能通过视图向源表新增记录?
二、vfp中能不能通过视图对源表删除记录?
[解决办法]
VFP远程视图使用面面观
http://qjh33.blog.163.com/blog/static/408600622011330053987/
*---------------先代码建立并设置可更新远程视图
Public gcDSNLess,gnViewConn
gcDSNLess='DRIVER=Sql Server;SERVER=计算机名或IP;UID=用户名;PWD=密码;APP=Microsoft Visual FoxPro;WSID=计算机名或IP;DATABASE=数据库名;Network=DBMSSOCN;Address=计算机名或IP,1433'
Create Database MyData
Create Connection MyStaffInfoConn Connstring gcDSNLess
Create Sql View MyStaffInfoView Remote Connection MyStaffInfoConn;
AS Select *;
FROM dbo.StaffInfo Staffinfo;
ORDER By Staffinfo.部门号, Staffinfo.分部门号, Staffinfo.工号
ThisView="MyStaffInfoView"
DBSetProp(ThisView,"View","SendUpdates",.T.)
DBSetProp(ThisView,"View","BatchUpdateCount",1)
DBSetProp(ThisView,"View","CompareMemo",.T.)
DBSetProp(ThisView,"View","FetchAsNeeded",.F.)
DBSetProp(ThisView,"View","FetchMemo",.T.)
DBSetProp(ThisView,"View","FetchSize",-1)
DBSetProp(ThisView,"View","MaxRecords",-1)
DBSetProp(ThisView,"View","Prepared",.F.)
DBSetProp(ThisView,"View","ShareConnection",.F.)
DBSetProp(ThisView,"View","AllowSimultaneousFetch",.F.)
DBSetProp(ThisView,"View","UpdateType",1)
DBSetProp(ThisView,"View","UseMemoSize",255)
DBSetProp(ThisView,"View","Tables","dbo.StaffInfo")
DBSetProp(ThisView,"View","WhereType",3)
DBSetProp(ThisView+".部门号","Field","DataType","C(10)")
DBSetProp(ThisView+".部门号","Field","UpdateName","dbo.StaffInfo.部门号")
DBSetProp(ThisView+".部门号","Field","KeyField",.F.)
DBSetProp(ThisView+".部门号","Field","Updatable",.T.)
DBSetProp(ThisView+".部门名称","Field","DataType","C(20)")
DBSetProp(ThisView+".部门名称","Field","UpdateName","dbo.StaffInfo.部门名称")
DBSetProp(ThisView+".部门名称","Field","KeyField",.F.)
DBSetProp(ThisView+".部门名称","Field","Updatable",.T.)
DBSetProp(ThisView+".分部门名称","Field","DataType","C(20)")
DBSetProp(ThisView+".分部门名称","Field","UpdateName","dbo.StaffInfo.分部门名称")
DBSetProp(ThisView+".分部门名称","Field","KeyField",.F.)
DBSetProp(ThisView+".分部门名称","Field","Updatable",.T.)
DBSetProp(ThisView+".工号","Field","DataType","I")
DBSetProp(ThisView+".工号","Field","UpdateName","dbo.StaffInfo.工号")
DBSetProp(ThisView+".工号","Field","KeyField",.F.)
DBSetProp(ThisView+".工号","Field","Updatable",.T.)
DBSetProp(ThisView+".姓名","Field","DataType","C(20)")
DBSetProp(ThisView+".姓名","Field","UpdateName","dbo.StaffInfo.姓名")
DBSetProp(ThisView+".姓名","Field","KeyField",.F.)
DBSetProp(ThisView+".姓名","Field","Updatable",.T.)
DBSetProp(ThisView+".auto_id","Field","DataType","N(20)")
DBSetProp(ThisView+".auto_id","Field","UpdateName","dbo.StaffInfo.Auto_ID")
DBSetProp(ThisView+".auto_id","Field","KeyField",.T.)
DBSetProp(ThisView+".auto_id","Field","Updatable",.F.)
Use (ThisView) In 0
Select (ThisView)
CursorSetProp("Buffering", 5, ThisView)
gnViewConn = CursorGetProp("CONNECTHANDLE",ThisView)
*这里数据更改、删除、增加代码略
*--------------然后更新远程视图
(开始一个 VFP 事务处理和一个服务器上(如:SQL Server)的事务处理)
Begin Transaction
SQLExec(gnViewConn,'BEGIN TRANSACTION')
llSuccess=Tableupdate(1,.F.,'MyStaffInfoView')
If llSuccess
SQLExec(gnViewConn,'IF @@TRANCOUNT>0 COMMIT TRAN')
End Transaction
Else
MyWriteShowOdbcErr("保存失败!操作将还原。")&& 我的自定义函数
SQLExec(gnViewConn,'IF @@TRANCOUNT>0 ROLLBACK TRAN')
Rollback
Tablerevert(.T.,'MyStaffInfoView')
Endif
*REQUERY('MyStaffInfoView') &&可略