将DBF表导入到SQLSERVER中的函数计算机二级考试
文章作者 100test 发表时间 2009:07:25 10:45:57
来源 100Test.Com百考试题网
给大家一个自已写的将DBF表导入到SQL SERVER数据库中的函数
我一直在我的程序中用,方便不少
请多多指都教,有什么问题可以回帖或邮[email protected]
连接句柄为CON,可以调用本函数之前执行如下语句CON=SQLSTRINGCONNECT("DRIVER=SQL SERVER.SERVER=(LOCAL).UID=SA.PWD=.DATABASE=你的数据库名")
***dbftosql()
PROCEDURE DBFTOSQL
PARA MDBF
LOCAL I,MFIELD,MTYPE,MCOLUMN,MSQLTYPE,MLEN,MSQL1,MSQL2
MFIELD=
MTYPE=
MCOLUMN=
MSQLTYPE=
MLEN=
MSQL1=
MSQL2=
IF !USED(MDBF)
USE &.MDBF
ENDI
SELE &.MDBF
I=1
DO WHILE !EMPTY(FIELD(I))
MFIELD=FIELD(I)
MTYPE=TYPE(MFIELD)
DO CASE
CASE UPPER(TYPE(MFIELD))= C
MSQLTYPE= CHAR
CASE UPPER(TYPE(MFIELD))= Y
MSQLTYPE= MONEY
CASE UPPER(TYPE(MFIELD))= D
MSQLTYPE= DATETIME
CASE UPPER(TYPE(MFIELD))= T
MSQLTYPE= DATETIME
CASE UPPER(TYPE(MFIELD))= B
MSQLTYPE= FLOAT
CASE UPPER(TYPE(MFIELD))= F
MSQLTYPE= FLOAT
CASE UPPER(TYPE(MFIELD))= G
MSQLTYPE= IMAGE
CASE UPPER(TYPE(MFIELD))= I
MSQLTYPE= INT
CASE UPPER(TYPE(MFIELD))= L
MSQLTYPE= BIT
CASE UPPER(TYPE(MFIELD))= M
MSQLTYPE= TEXT
CASE UPPER(TYPE(MFIELD))= N
MSQLTYPE= FLOAT
ENDCASE
IF C $MTYPE
MLEN= ( ALLT(STR(LEN(&.MFIELD))) )
ELSE
MLEN=
ENDI
IF EMPTY(MCOLUMN)
MCOLUMN=FIELD(I) SPACE(1) ALLT(MSQLTYPE) MLEN
ELSE
MCOLUMN=MCOLUMN , FIELD(I) SPACE(1) ALLT(MSQLTYPE) MLEN
ENDI
IF EMPTY(MSQL1)
MSQL1=FIELD(I)
ELSE
MSQL1=MSQL1 , FIELD(I)
ENDI
IF EMPTY(MSQL2)
MSQL2= ? FIELD(I)
ELSE
MSQL2=MSQL2 ,? FIELD(I)
ENDI
I=I 1
ENDD
MSQL= CREATE TABLE MDBF SPACE(1) ( MCOLUMN )
IF SQLEXEC(CON,MSQL)=1
ENDI
IF RECCOUNT()>.0
GO TOP
DO WHILE !EOF()
I=1
DO WHILE !EMPTY(FIELD(I))
XX=FIELD(I)
IF XX=.NULL.
REPL &.XX WITH
ENDI
I=I 1
ENDD
MSQL= INSERT INTO MDBF SPACE(1) ( MSQL1 ) SPACE(1) VALUES ( MSQL2 )
IF SQLEXEC(CON,MSQL)=1
ENDI
SKIP
ENDD
ENDI
USE IN &.MDBF
RETU