Note: The dbf database structure must be consistent with the sql table
<%
Dim conndbf_dbf,Driver_dbf,SourceType_dbf,DBPath_dbf
dim Conn_sql,StrCnn,i,str_dbf
dim dbf_table_name,sql_table_name
'dbf database name
dbf_table_name="20005070"
'sql table name
sql_table_name="zjls"
str_dbf=""
'Create dbfConnection object
Set conn_dbf = Server.CreateObject("ADODB.Connection")
Driver_dbf = "Driver={Microsoft Visual FoxPro Driver};"
SourceType_dbf = "SourceType=DBF;"
'datadbf is the directory where the dbf database is located
DBPath_dbf = "SourceDB=" & Server.MapPath( "datadbf" )
' Call the Open method to open the database
conn_dbf.Open Driver_dbf & SourceType_dbf & DBPath_dbf
Set rd_dbf= Server.CreateObject("ADODB.Recordset")
'Open the DBF file, the second parameter is the Connection object
rd_dbf.Open "select * from "&dbf_table_name, conn_dbf, 2, 2
'Create sqlConnection object
Set conn_sql = Server.CreateObject("ADODB.Connection")
'Initial Catalog is the sql database name, Data Source is the local name
StrCnn = "Provider=sqloledb; User ID=sa; Password=; Initial Catalog=jz30data; Data Source=chaihua"
Conn_sql.OpenStrCnn
Set CreateDbfRecordset_sql= Server.CreateObject("ADODB.Recordset")
'Open the DBF file, the second parameter is the Connection object
' www.downcodes.com
rd_dbf.movefirst
Do While Not rd_dbf.Eof
'Construct the field string read from the DBF database
str_dbf=""
for i=1 to 38
str_dbf=str_dbf&",'"&rd_dbf.fields(i)&"'"
next
str_dbf="'"&rd_dbf.fields(0)&"'"&str_dbf
'Insert into sql table
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("Submission successful!")
%>
Author: Chai Hua QQ:57302017