[此贴子已经被作者于2006-11-23 16:05:45编辑过]
发现vfp中用copy to array a, insert into ddd from array a 能区分字段名添加记录,但不知道spt传到sql时会不会出错
connectstring='driver=sql server;server=server;'+'database=NORTHWIND;uid=sa;pwd='
gnConnHandle=SQLstringCONNECT(connectstring)
SQLEXEC(gnConnHandle,"SELECT * FROM categories","order125
SELECT order125
BROWSE
CURSORSETPROP("Tables","categories","order125")
CURSORSETPROP("KeyFieldList","categoryid","order125")
CURSORSETPROP("UpdatableFieldList" ,"categoryid,categoryname,","order125")
CURSORSETPROP("UpdateNameList","categoryid categories.categoryid,categoryname categories.categoryname,"order125")
CURSORSETPROP("UpdateNameList","categoryid categories.categoryid,categoryname categories.categoryname","order125")
CURSORSETPROP("SendUpdates" ,.t.,"order125")
SQLEXEC(gnConnHandle,"SET IDENTITY_INSERT on","order125")
SELECT order125
BROWSE
在插入一条记录时,本地的能看到已经加入,但数据源那里报错了,还是说IDENTITY_INSERT 为off,不能写入,怎样才能将 IDENTITY INSERT 设为on??
更恐怖的是我要关闭order125都不行了,老是出来个报错的,但不知怎么退出,只能重启vfp。盼,高手指教了[此贴子已经被作者于2006-11-21 15:23:47编辑过]
自己回答了
将本地的表追加到服务器sql表中
lcField2="(AUTOID,code,price)"&&sql表里的字段
lcvalues2="(?T2.AUTOID,?T2.code,?T2.price)"&&本地表里的字段
lcInsert2="Insert Into vouchs"+lcField2 +"values"+lcvalues2 &&vouchs为sql的表名
USE vouchSa ALIAS T2
SCAN
lnReturn2=SQLExec(gnConnHandle,lcInsert2)
ENDSCAN
?lnReturn2 &&1为更新,-1为失败
CLOSE ALL
SQLDISCONNECT(gnConnHandle)
CLOSE ALL