主题:如何将Microsoft Access中表转为 FoxPro表
youyou168
[专家分:0] 发布于 2008-07-02 14:31:00
如何将Microsoft Access中表转为 FoxPro表 命令是???
回复列表 (共6个回复)
沙发
cbl518 [专家分:57140] 发布于 2008-07-02 15:38:00
vfp 没有直接的语句,可直接导入的。
用 ODBC 连接的方式!!!
板凳
CCB2000 [专家分:690] 发布于 2008-07-06 09:10:00
参考一下:
*PROC xbldsqlview
PARAMETER m.q_fsqlviewdbc,m.q_flocaldbc,m.q_dsn,m.q_userid,m.q_password,m.q_dbctype
* m.q_fsqlviewdbc =
* m.q_flocaldbc =
* m.q_dsn =
* m.q_userid =
* m.q_password =
* m.q_dbctype =
SET STEP OFF
SET ECHO OFF
SET DEBUG OFF
SET ESCAPE OFF
SET TALK OFF
SET SAFETY OFF
_SCREEN.VISIBLE=.T.
CLOSE DATABASE ALL
CLOSE TABLES ALL
=sqldisconnect(0)
IF TYPE("m.q_fsqlviewdbc")#"C"
m.q_fsqlviewdbc=""
ENDI
m.q_fsqlviewdbc=UPPE(ALLTRIM(m.q_fsqlviewdbc))
IF ALLTRIM(m.q_fsqlviewdbc)==""
RETU .F.
ENDI
m.q_fsqlviewdbc=IIF(RAT(".",m.q_fsqlviewdbc)>0,LEFT(m.q_fsqlviewdbc,RAT(".",m.q_fsqlviewdbc)-1),m.q_fsqlviewdbc)+"."+"DBC"
IF TYPE("m.q_flocaldbc")#"C"
m.q_flocaldbc=""
ENDI
m.q_flocaldbc=ALLTRIM(m.q_flocaldbc)
IF ALLTRIM(m.q_flocaldbc)==""
m.q_flocaldbc=IIF(RAT("\",m.q_fsqlviewdbc)>0,LEFT(m.q_fsqlviewdbc,RAT("\",m.q_fsqlviewdbc)-1)+"\"+"..\LOCAL"+"\"+SUBS(m.q_fsqlviewdbc,RAT("\",m.q_fsqlviewdbc)+1),"..\LOCAL"+"\"+m.q_fsqlviewdbc)
ENDI
*IF ALLTRIM(m.q_flocaldbc)==""
* RETU .F.
*ENDI
IF TYPE("m.q_dsn")#"C"
m.q_dsn=""
ENDI
m.q_dsn=ALLTRIM(m.q_dsn)
IF ALLTRIM(m.q_dsn)==""
RETU .F.
ENDI
IF TYPE("m.q_userid")#"C"
m.q_userid=""
ENDI
m.q_userid=ALLTRIM(m.q_userid)
*IF ALLTRIM(m.q_userid)==""
* RETU .F.
*ENDI
IF TYPE("m.q_password")#"C"
m.q_password=""
ENDI
m.q_password=ALLTRIM(m.q_password)
*IF ALLTRIM(m.q_password)==""
* RETU .F.
*ENDI
IF TYPE("m.q_dbctype")#"C"
m.q_dbctype=""
ENDI
m.q_dbctype=UPPE(ALLTRIM(m.q_dbctype))
*IF ALLTRIM(m.q_dbctype)==""
* RETU .F.
*ENDI
PRIVATE m.q_connect
m.q_connect="connect1"
?'CREATE DATABASE "&q_fsqlviewdbc"'
CLOSE DATABASE ALL
CLOSE TABLES ALL
PRIVATE m.q_blocksize
m.q_blocksize=SET("BLOCKSIZE")
SET BLOCKSIZE TO 0
CREATE DATABASE "&q_fsqlviewdbc"
SET BLOCKSIZE TO m.q_blocksize
CLOSE DATABASE ALL
CLOSE TABLES ALL
IF !FILE(m.q_fsqlviewdbc)
CLOSE DATABASE ALL
CLOSE TABLES ALL
=sqldisconnect(0)
RETU .F.
ENDI
PRIVATE m.q_dbcsql
m.q_dbcsql=m.q_flocaldbc
m.q_dbcsql=IIF(RAT("\",m.q_dbcsql)>0,SUBS(m.q_dbcsql,RAT("\",m.q_dbcsql)+1),m.q_dbcsql)
m.q_dbcsql=IIF(RIGHT(m.q_dbcsql,LEN("."+"DBC"))="."+"DBC",LEFT(m.q_dbcsql,LEN(m.q_dbcsql)-LEN("."+"DBC")),m.q_dbcsql)
CLOSE DATABASE ALL
CLOSE TABLES ALL
OPEN DATABASE "&q_fsqlviewdbc" EXCLUSIVE
?'CREATE CONNECTION "&q_connect"'
*CREATE CONNECTION "&q_connect" DATASOURCE "&q_dsn" USERID "&q_userid" PASSWORD "&q_password" DATABASE "&q_dbcsql"
CREATE CONNECTION "&q_connect" DATASOURCE "&q_dsn" USERID "&q_userid" PASSWORD "&q_password"
=DBSETPROP("&q_connect",'Connection','Asynchronous',.F.)
=DBSETPROP("&q_connect",'Connection','BatchMode',.T.)
=DBSETPROP("&q_connect",'Connection','Comment','')
*DBSETPROP("&q_connect",'Connection','ConnectString','')
=DBSETPROP("&q_connect",'Connection','ConnectTimeOut',0)
*DBSETPROP("&q_connect",'Connection','Database',"&q_dbcsql")
*DBSETPROP("&q_connect",'Connection','DataSource',"&q_dsn")
=DBSETPROP("&q_connect",'Connection','DispLogin',3)
=DBSETPROP("&q_connect",'Connection','DispWarnings',.F.)
=DBSETPROP("&q_connect",'Connection','IdleTimeOut',0)
=DBSETPROP("&q_connect",'Connection','PacketSize',4096)
*DBSETPROP("&q_connect",'Connection','PassWord',"&q_password")
=DBSETPROP("&q_connect",'Connection','QueryTimeOut',0)
=DBSETPROP("&q_connect",'Connection','Transactions',1)
*DBSETPROP("&q_connect",'Connection','UserId',"&q_userid")
=DBSETPROP("&q_connect",'Connection','WaitTime',100)
IF !sqlgetprop(0,'DispLogin')=3
=sqlsetprop(0,'DispLogin',3)
ENDI
IF !sqlgetprop(0,'DispWarnings')=.F.
=sqlsetprop(0,'DispWarnings',.F.)
ENDI
IF !DBGETPROP(m.q_connect,'CONNECTION','DispLogin')=3
=DBSETPROP(m.q_connect,'CONNECTION','DispLogin',3)
ENDI
IF !DBGETPROP(m.q_connect,'CONNECTION','DispWarnings')=.F.
=DBSETPROP(m.q_connect,'CONNECTION','DispWarnings',.F.)
ENDI
#IF ROUND(VAL(CHRTRAN(UPPE(VERSION()),"MICROSOFTVISUALFOXPRO","")),2)>=8.0
#ELSE
IF !DBGETPROP(m.q_connect,'CONNECTION','UserId')==m.q_userid
=DBSETPROP(m.q_connect,'CONNECTION','UserId',m.q_userid)
ENDI
IF !DBGETPROP(m.q_connect,'CONNECTION','PassWord')==m.q_password
=DBSETPROP(m.q_connect,'CONNECTION','PassWord',m.q_password)
ENDI
#ENDI
PRIVATE m.q_path0
m.q_path0=SYS(5)+SYS(2003)
#IF ROUND(VAL(CHRTRAN(UPPE(VERSION()),"MICROSOFTVISUALFOXPRO","")),2)>=8.0
PRIVATE m.q_connecthandle
m.q_connecthandle=SQLCONNECT(m.q_connect,m.q_userid,m.q_password,.T.)
#ELSE
PRIVATE m.q_connecthandle
m.q_connecthandle=SQLCONNECT(m.q_connect)
#ENDI
SET DEFAULT TO (m.q_path0)
IF !m.q_connecthandle>0
CLOSE DATABASE ALL
CLOSE TABLES ALL
=sqldisconnect(0)
RETU .F.
ENDI
=sqltables(m.q_connecthandle,"'TABLE','VIEW'","xbldtmp")
IF !USED("xbldtmp")
CLOSE DATABASE ALL
CLOSE TABLES ALL
=sqldisconnect(0)
RETU .F.
ENDI
下续。。。
3 楼
CCB2000 [专家分:690] 发布于 2008-07-06 09:10:00
SELE xbldtmp
DO CASE
CASE INLIST(m.q_dbctype,"ORACLE")
* ORACLE
IF !ALLTRIM(m.q_userid)==""
SET FILT TO UPPE(ALLTRIM(table_owner))==UPPE(ALLTRIM("&q_userid")).OR.UPPE(ALLTRIM(table_owner))==UPPE(ALLTRIM("dbo"))
ELSE
SET FILT TO UPPE(ALLTRIM(table_owner))==UPPE(ALLTRIM("dbo"))
ENDI
CASE INLIST(m.q_dbctype,"MSSQL","SQL")
* MSSQL
IF !ALLTRIM(m.q_userid)==""
SET FILT TO UPPE(ALLTRIM(table_schem))==UPPE(ALLTRIM("&q_userid")).OR.UPPE(ALLTRIM(table_schem))==UPPE(ALLTRIM("dbo"))
ELSE
SET FILT TO UPPE(ALLTRIM(table_schem))==UPPE(ALLTRIM("dbo"))
ENDI
OTHER
* ACCESS及其它
SET FILT TO
ENDC
GOTO TOP
SCAN REST
PRIVATE m.q_table_name
m.q_table_name=ALLTRIM(table_name)
IF UPPE(ALLTRIM(m.q_table_name))==UPPE(ALLTRIM("dtproperties")).OR.;
UPPE(ALLTRIM(m.q_table_name))=UPPE(ALLTRIM("sys"))
LOOP
ENDI
PRIVATE m.q_view_name
m.q_view_name=m.q_table_name
PRIVATE m.q_selectexp
m.q_selectexp='SELECT * FROM "&q_table_name"'
PRIVATE m.q_whereexp
m.q_whereexp=""
m.q_view_name=UPPE(m.q_view_name)
?'CREATE SQL VIEW "&q_view_name"'
CREATE SQL VIEW "&q_view_name" CONNECTION "&q_connect" ;
AS &q_selectexp &q_whereexp
=DBSETPROP("&q_view_name",'View','BatchUpdateCount',1)
=DBSETPROP("&q_view_name",'View','Comment','')
=DBSETPROP("&q_view_name",'View','CompareMemo',.T.)
*DBSETPROP("&q_view_name",'View','ConnectName','')
=DBSETPROP("&q_view_name",'View','FetchAsNeeded',.F.)
=DBSETPROP("&q_view_name",'View','FetchMemo',.T.)
=DBSETPROP("&q_view_name",'View','FetchSize',-1)
=DBSETPROP("&q_view_name",'View','MaxRecords',-1)
*DBSETPROP("&q_view_name",'View','Offline',.F.)
*DBSETPROP("&q_view_name",'View','ParameterList','')
*如果Prepared=.T.且ShareConnection=.T.,REQUERY()时会发生#1542错误
*(Base table fields have been changed and no longer match view fields. View field properties cannot be set.)
=DBSETPROP("&q_view_name",'View','Prepared',.F.)
*DBSETPROP("&q_view_name",'View','RuleExpression','')
*DBSETPROP("&q_view_name",'View','RuleText','')
=DBSETPROP("&q_view_name",'View','SendUpdates',.T.)
=DBSETPROP("&q_view_name",'View','ShareConnection',.T.)
*DBSETPROP("&q_view_name",'View','SourceType',2)
*DBSETPROP("&q_view_name",'View','SQL','')
=DBSETPROP("&q_view_name",'View','Tables',"&q_table_name")
=DBSETPROP("&q_view_name",'View','UpdateType',1)
=DBSETPROP("&q_view_name",'View','UseMemoSize',255)
=DBSETPROP("&q_view_name",'View','WhereType',1)
SELE xbldtmp
ENDS
SELE xbldtmp
USE
=sqldisconnect(m.q_connecthandle)
CLOSE DATABASE ALL
CLOSE TABLES ALL
OPEN DATABASE "&q_fsqlviewdbc" EXCLUSIVE
VALIDATE DATABASE
PACK DATABASE
CLOSE DATABASE ALL
CLOSE TABLES ALL
CLOSE DATABASE ALL
CLOSE TABLES ALL
=sqldisconnect(0)
RETU .T.
* END OF PROC XBLDSQLVIEW.
4 楼
0901chang [专家分:10660] 发布于 2008-07-06 11:54:00
楼上两位仁兄,乌鸦也想学Access转vfp,但想请你们这样教乌鸦
建立Access对象
打开指定的Access表
另存为vfp表
关闭Access对象
乌鸦比较土,尚未看过Access的资料,不知道能否这样做,在此先谢过。
5 楼
CCB2000 [专家分:690] 发布于 2008-07-06 14:18:00
上面的PROC xbldsqlview主要是建立一个包含远程视图的Vfp数据库,这样浏览查询其它数据库里的表、视图等数据就比较方便了。如果再设置好KeyField等属性,增加、修改、删除数据也是可以的。
例如VB98中有一个NWIND.MDB数据库,可以:
DO xbldsqlview WITH "NWIND.DBC","","NWIND","","",""
然后:
OPEN DATABASE ("NWIND.DBC")
MODIFY DATABASE
就可以浏览查询数据了,比在Access里浏览查询数据方便多了。
6 楼
0901chang [专家分:10660] 发布于 2008-07-06 14:59:00
多谢楼上,乌鸦尚未搞懂视图,以后一定凑时间认真地看一看视图。
我来回复