| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2664 人关注过本帖
标题:vfp如何向ACCESS表批量添加数据
只看楼主 加入收藏
yll148
Rank: 2
等 级:论坛游民
威 望:3
帖 子:268
专家分:15
注 册:2012-7-3
结帖率:87.5%
收藏
已结贴  问题点数:20 回复次数:15 
vfp如何向ACCESS表批量添加数据
vfp如何向ACCESS表批量添加数据,请各位高手指点,谢谢!!
搜索更多相关主题的帖子: 如何 
2016-10-22 21:41
hepingfly
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:15
帖 子:195
专家分:657
注 册:2015-5-21
收藏
得分:0 
像操作  SQLSERVER 表一样,先做连接,再 insert into 插入数据即可。

星际花草
2016-10-22 22:05
yll148
Rank: 2
等 级:论坛游民
威 望:3
帖 子:268
专家分:15
注 册:2012-7-3
收藏
得分:0 
SQLEXEC(MYCON1,'insert into 发出商品 select * from ls'这样吗?
2016-10-22 22:23
hepingfly
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:15
帖 子:195
专家分:657
注 册:2015-5-21
收藏
得分:5 
回复楼上:不行。想实现目的,有2个方法。
1.建立与 ACCESS表 的连接后,创建一张可更新的视图,用 go bottom ,append from  ...,从同结构的表中,一次性插入。
2.用 sqlexec(连接,'insert into 表(字段1,字段2, ..) values(值1,值2, ..)'}的方式,将每条记录的字段值,
  赋值给值1,值2,.. 的形式,一条条记录循环插入。
 注:第2种虽麻烦一点,但效率高。


星际花草
2016-10-23 22:13
tlliqi
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:204
帖 子:15453
专家分:65956
注 册:2006-4-27
收藏
得分:5 
以下是引用yll148在2016-10-22 22:23:06的发言:

SQLEXEC(MYCON1,'insert into 发出商品 select * from ls'这样吗?
要先建立与 ACCESS表 的连接
2016-10-23 23:11
yll148
Rank: 2
等 级:论坛游民
威 望:3
帖 子:268
专家分:15
注 册:2012-7-3
收藏
得分:0 
能给一个实例吗?谢谢!
2016-10-24 08:39
yll148
Rank: 2
等 级:论坛游民
威 望:3
帖 子:268
专家分:15
注 册:2012-7-3
收藏
得分:0 
能给一个实例吗?谢谢!
2016-10-24 08:42
ttlover7613
Rank: 2
等 级:论坛游民
威 望:2
帖 子:48
专家分:85
注 册:2016-8-29
收藏
得分:0 
我是将Oracle的数据上传到SQLserver,看有没有对你有帮助。
SET SAFETY OFF

release ALL
CLOSE ALL
SET DATE TO long
SET CENTURY on
SET HOURS TO 24

CLOSE DATABASES
OPEN DATABASE main.dbc
SET SAFETY OFF
SET CENTURY on
SET DATE  SHORT

IF USED('PAA1')
SELECT paa1
USE
ENDIF
IF USED('PAA')
SELECT paa
USE
ENDIF
IF USED('PAA2')
SELECT paa2
USE
ENDIF
IF USED('PAA3')
SELECT paa3
USE
ENDIF
IF USED('PAA5')
SELECT paa5
USE
ENDIF
IF USED('PAA6')
SELECT paa6
USE
ENDIF
IF USED('PAA7')
SELECT paa7
USE
ENDIF

DATE1=ALLTRIM(dtoc((THISFORM.TEXT1.Value)))
DATE2=ALLTRIM(dtoc((THISFORM.TEXT1.Value-1)))
CmessageText='正在处理数据,请耐心等待!'
h1=SQLCONNECT("orcl1")
IF h1<0
MESSAGEBOX('网络连接orcl未通,请检查线路!',0+64,'提示')
RETURN
ENDIF
h2=SQLCONNECT("yun")
IF h2<0
MESSAGEBOX('网络连接yun未通,请检查线路!',0+64,'提示')
RETURN
ENDIF

Pgh="select t.reg_number,t.reg_yb,t.reg_ybcardno,t.reg_id,sii_idcard,sii_sickman_code,sii_name,sii_birthday,sii_sex "
Pgh1=" from ad_sickman_info a right join ad_register t on sii_sickman_code = t.reg_id "
Pgh2=" where t.reg_number in (select distinct prm_number from ad_prescription_memo where to_char(prm_getmoney_date,'yyyy-mm-dd')='&date1' "
Pgh3=" and (prm_getmoney_date is not null) and (scrq is null))"
Zgh="&Pgh"+" "+"&Pgh1"+" "+"&Pgh2"+" "+"&Pgh3"
abb=SQLEXE(h1,Zgh,'hhh1')
wait window CmessageText at srow()/2,(scols()-len(CmessageText))/2  nowait
COPY TO paa7
SELECT 0
USE PAA7 ALIAS PAA7
SELECT paa7
IF RECCOUNT()=0
  SQLDISCONNECT(h1)
  SQLDISCONNECT(h2)
 CLOSE ALL
  CLOSE DATABASES
  Release ALL
  DELETE FILE paa7.dbf
RETURN
ELSE

GO top
DO WHILE NOT EOF()
IF reg_yb='0'
pkh=''
ELSE
  IF reg_yb='1' AND NOT ISNULL(reg_ybcard)
     pcd=LEN(ALLTRIM(reg_ybcard))
       IF pcd <15
         pkh=SUBSTR(reg_ybcard,1,5)
       ELSE
         IF (pcd >15) and (pcd <=22)
             pkh=SUBSTR(reg_ybcard,1,15)
         ELSE
             pkh=SUBSTR(reg_ybcard,1,18)
         ENDIF
       endif
           REPLACE  sii_idcard WITH '',reg_ybcard WITH pkh
   ENDIF
  ENDIF  
SKIP
enddo
SELECT paa7
INDEX on sii_sickma to sy

**科室库**
abb=SQLEXEC(h1,"select t.*, t.rowid from as_department t",'hhh2')
wait window CmessageText at srow()/2,(scols()-len(CmessageText))/2  nowait
COPY TO PAA2
SELECT 0
USE PAA2 ALIAS PAA2
INDEX on dep_code TO sy3
**医生库**
abb=SQLEXEC(h1,"select t.*, t.rowid from as_employee t",'hhh3')
wait window CmessageText at srow()/2,(scols()-len(CmessageText))/2  nowait
COPY TO PAA3
SELECT 0
USE PAA3 ALIAS PAA3
*yaopin*
abb=SQLEXEC(h1,"select t.med_code,t.med_yl from as_med_dict t",'hhh10')
wait window CmessageText at srow()/2,(scols()-len(CmessageText))/2  nowait
COPY TO Paa10
SELECT 0
USE paa10 ALIAS paa10
***是否输液口服
abb=SQLEXEC(h1,"select t.aek_code,t.aek_name from as_advice_exe_kind t ",'hhh11')
wait window CmessageText at srow()/2,(scols()-len(CmessageText))/2  nowait
COPY TO Paa11
SELECT 0
USE paa11 ALIAS paa11

YU1="select prm_jl,prm_pres_num,prm_mecode,prm_id,prm_medname,prm_model,prm_getmoney_date,prm_number,prm_sell_price,prm_countnum-prm_exitnum,prm_if_medexa,bs,prm_dep2,prm_doccode,scrq,prm_aday_degree,prm_adegree_num,prm_zyyf,prm_memo,prm_sunit  "
YU2=",prm_money_kind from ad_prescription_memo where to_char(prm_getmoney_date,'yyyy-mm-dd')='&date1' "
YU3=" and (prm_getmoney_date is not null) and (scrq is null)"
YU="&yu1"+" "+"&Yu2"+" "+"&Yu3"
abb=SQLEXEC(h1,yu)
wait window CmessageText at srow()/2,(scols()-len(CmessageText))/2  nowait
COPY TO paa1
SELECT 0
USE paa1  ALIAS paa1
SELECT paa1
SET FILTER TO subs(alltrim(prm_money_),1,4)='0114'
REPLACE ALL prm_if_med WITH '1'
SET FILTER to
SELECT a.prm_jl,a.prm_pres_n,a.prm_sunit,a.prm_id,a.prm_mednam,a.prm_model,a.prm_number,a.prm_getmon,a.prm_sell_p,a.prm_countn,b.dep_name,c.emp_name,a.prm_if_med,a.bs,a.scrq,a.prm_aday_d,a.prm_adegre,a.prm_zyyf,d.reg_yb,d.reg_ybcard,d.sii_idcard,d.sii_name,e.med_yl,f.aek_name FROM paa1 a  INNER JOIN  paa2 b ON a.prm_dep2=b.dep_code INNER JOIN paa3 c ON  a.prm_doccod =c.emp_code left JOIN paa7 d ON  a.prm_number=d.reg_number LEFT JOIN paa10 e ON a.prm_mecode=e.med_code LEFT JOIN paa11 f ON a.prm_memo=f.aek_code   INTO TABLE paa5
SELECT paa5
GO top
SET FILTER TO ISNULL(scrq) AND (prm_countn <>0)
DO WHILE NOT EOF()
Pcfh=prm_number
Pmc=prm_mednam
pys=emp_name
psl=prm_countn
pjl=prm_jl
pdw=prm_sunit
pxm1=sii_name
psfrq=TTOC(prm_getmon)
DO CASE
CASE  ALLTRIM(prm_if_med)='0'
pcflb='3'
case ALLTRIM(prm_if_med)='1'
pcflb='1'
otherwise
pcflb=''
ENDCASE

IF reg_yb='0'
ppkh=''
ELSE
  IF ISNULL(reg_ybcard)
     ppkh=ALLTRIM(sii_idcard)
  ELSE
     ppkh=ALLTRIM(REG_YBCARD)
  ENDIF
ENDIF   
IF ISNULL(pdw)
   pzs='数量:'+ALLTRIM(str(psl))
ELSE
   pzs='数量:'+ALLTRIM(str(psl))+ALLTRIM(pdw)
 endif  
pnr='用法:'+ALLTRIM(prm_adegre)+' '+ALLTRIM(med_yl)+' '+ALLTRIM(aek_name)
pnr2='每天'+ALLTRIM(prm_aday_d)+'次'
pnr3=ALLTRIM(prm_zyyf)
IF prm_if_med ='2'
   pznr=pzs
  ELSE
    IF prm_if_med ='0'
       IF ISNULL(prm_zyyf)
          pznr=pzs+', '+pnr+','+pnr2+''
       ELSE
          pznr='数量:'+ALLTRIM(pjl)+'× '+ALLTRIM(STR(prm_pres_n))+'剂,'+pnr3
       endif   
ELSE
pznr=''
ENDIF
endif

prq=DTOC(DATE())
pzf="insert into Health_Data([Inspect_ID] ,[UserID] ,[InTheDate],[Inspect_category] ,[Inspect_name] ,[Inspect_part],[Inspect_content],[Chronic_mark] ,[Docter] ,cardid,name)"
pzf2="values('&pcfh','','&psfrq','&pcflb',"
pzf3="'&pmc','',"
pzf4="'&pznr',"
pzf5="0,'&pys','&ppkh','&pxm1')"
zzf="&pzf"+" "+"&pzf2"+"&pzf3"+"&pzf4"+"&pzf5"
SQLEXEC(h2,zzf)
wait window CmessageText at srow()/2,(scols()-len(CmessageText))/2  nowait
SQLEXEC(h1,"update ad_prescription_memo set scrq='&prq' where prm_number='&pcfh'")
wait window CmessageText at srow()/2,(scols()-len(CmessageText))/2  nowait
SKIP
enddo
ENDIF
SQLDISCONNECT(h1)
SQLDISCONNECT(h2)
CLOSE ALL
CLOSE DATABASES
release ALL
DELETE FILE paa1.dbf
DELETE FILE paa2.dbf
DELETE FILE paa7.dbf
DELETE FILE paa5.dbf
DELETE FILE paa10.dbf
DELETE FILE paa11.dbf
DELETE FILE paa3.dbf
DELETE FILE paa3.fpt
DELETE FILE paa2.fpt
DELETE FILE sy3.idx
DELETE FILE sy.idx







[此贴子已经被作者于2016-10-24 11:17编辑过]

2016-10-24 11:13
厨师王德榜
Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18
等 级:贵宾
威 望:199
帖 子:991
专家分:4966
注 册:2013-2-16
收藏
得分:0 
推荐用
Scan
    insert into ...
endscan
这种结构,话说你连接既然已经没问题了,添加的话,和向SQLServer中添加没什么两样。
2016-10-24 11:24
yll148
Rank: 2
等 级:论坛游民
威 望:3
帖 子:268
专家分:15
注 册:2012-7-3
收藏
得分:0 
非常感谢8楼的朋友,我看了一下,最终还是用 sqlexec(连接,'insert into 表(字段1,字段2, ..) values(值1,值2, ..)'}的方式,将每条记录的字段值,
  赋值给值1,值2,.. 的形式,一条条记录循环插入的,可是我按上述方法使用仍没有将数据添加到ACCESS表中,我实在太笨了。还得麻烦各位高手指导。谢谢!
2016-10-24 12:41
快速回复:vfp如何向ACCESS表批量添加数据
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.067924 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved