說明:dbf數據庫結構要與sql表一致
<%
Dim conndbf_dbf,Driver_dbf,SourceType_dbf,DBPath_dbf
dim Conn_sql ,StrCnn,i,str_dbf
dim dbf_table_name,sql_table_name
'dbf數據庫名稱
dbf_table_name="20005070"
'sql表名稱
sql_table_name="zjls"
str_dbf=""
' 建立dbfConnection 對象
Set conn_dbf = Server.CreateObject("ADODB.Connection")
Driver_dbf = "Driver={Microsoft Visual FoxPRo Driver};"
SourceType_dbf = "SourceType=DBF;"
'datadbf為dbf數據庫所在目錄
DBPath_dbf = "SourceDB=" & Server.MapPath( "datadbf" )
' 調用Open 方法打開數據庫
conn_dbf.Open Driver_dbf & SourceType_dbf & DBPath_dbf
Set rd_dbf= Server.CreateObject("ADODB.Recordset")
' 打開DBF文件,參數二為Connection對象
rd_dbf.Open "select * from "&dbf_table_name, conn_dbf, 2, 2
'建立sqlConnection 對象
Set conn_sql = Server.CreateObject("ADODB.Connection")
'Initial Catalog為sql數據庫名,Data Source為本機名
StrCnn = "Provider=sqloledb; User ID=sa; PassWord=; Initial Catalog=jz30data; Data Source=chaihua"
Conn_sql.Open StrCnn
Set CreateDbfRecordset_sql= Server.CreateObject("ADODB.Recordset")
' 打開DBF文件,參數二為Connection對象
' www.knowsky.com
rd_dbf.movefirst
Do While Not rd_dbf.Eof
'構造從DBF數據庫讀出的字段字符串
str_dbf=""
for i=1 to 38
str_dbf=str_dbf&",'"&rd_dbf.fIElds(i)&"'"
next
str_dbf="'"&rd_dbf.fIElds(0)&"'"&str_dbf
'插入sql表
CreateDbfRecordset_sql.Open "insert "&sql_table_name&" values("&str_dbf&")", conn_sql,2,2
rd_dbf.MoveNext
Loop
conn_sql.close
conn_dbf.close
response.write("提交成功!")
%>