ASP中实现从DBF数据库导出数据到SQL表
类别: ASP教程
说明: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对象
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("提交成功!")
%>
<%
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对象
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("提交成功!")
%>
-= 资 源 教 程 =-
文 章 搜 索