說明: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.downcodes.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("提交成功!")
%>
作者:柴華QQ:57302017