如何用临时表更新SQL后台数据表?
vfp连接的SQL网络数据库,gril的数据源是语句生成的临时表,能否通过修改临时表,更新后台数据表?
[解决办法]
临时表更新SQL表的例子:*------------------------SQL服务器名:MyServerSQL用户名:saSQL用户名:空SQL中的表名:Kq_YgKq_Yg表的字段: Id Int 4Name Char 10Department Char 20以下是FORM信息:Form上有5个按钮,一个Grid,分别为:1、增加(AddCmd),Click事件:Select Temp1Append BlankThisform.SaveCmd.Enabled=.T.Thisform.Grid1.RefreshThisform.Grid1.ReadOnly=.F.Thisform.Grid1.SetFocus2、修改(EditCmd),Click事件:Thisform.SaveCmd.Enabled=.T.Thisform.Grid1.ReadOnly=.F.Thisform.Grid1.SetFocus3、删除(DelCmd),Click事件:DeleteThisform.Grid1.RefreshThisform.SaveCmd.Enabled=.T.4、保存(SaveCmd),此按钮的Enabled值为.F.,Click事件:Select Temp1lSuccess=CursorSetProp("sendupdates",.T.,"Temp1")&&设置为可更新m.lSuccess=Tableupdate(.T.,.F.) &&successful updateIf m.lSuccess Messagebox("保存成功!",64,"信息提示") Thisform.SaveCmd.Enabled=.F. Thisform.Grid1.ReadOnly=.T.Else Messagebox("保存失败!",16,"信息提示") Thisform.SaveCmd.Enabled=.T. Thisform.Grid1.ReadOnly=.F. Tablerevert(.T.)Endif5、退出(ExitCmd),Click事件:SQLDisconnect(0) &&终止所有活动的连接。Close DatabasesThisform.Release6、Grid的ReadOnly值为.T.7、Form的Init事件:Close DatabasesSet Safety OffPublic nhandlenhandle=Sqlstringconnect("driver=SQL Server;server=MyServer;uid=sa;pwd=;database=MyServer")If nhandle<=0 Messagebox("连接SQL Server 失败!!!",16, '错误信息') CancelElse Thisform.Grid1.RecordSource=Null Ac=SQLExec(nhandle,"Select * From Kq_Yg","Temp1") If Ac<0 Messagebox("读取数据错误!",16, '错误信息') Cancel Endif Select Temp1 Thisform.Grid1.RecordSource='Temp1' Thisform.Grid1.Refresh Set Multilocks On CursorSetProp("tables","Kq_Yg","Temp1") &&设置临时表的更新目标表 CursorSetProp("keyfieldlist","ID","Temp1") &&设置临时表的关键字 CursorSetProp("UpdateType",1,"Temp1") &&设置用新数据更新旧数据 CursorSetProp("updatablefieldlist","ID,Name,Department","Temp1")&&设置临时表的更新字段 CursorSetProp("updatenamelist","ID Kq_Yg.ID ,Name Kq_Yg.Name,Department Kq_Yg.Department","Temp1") &&&用Temp1中的相应字段更新Kq_Yg表 CursorSetProp("wheretype",2) CursorSetProp("buffering",5)&&设置表缓冲Endif