如何在ASP中访问和修改DBF数据表(单个DBF文件)(高分相送,在线等待)

yusiyin 2003-09-12 02:04:23
我用ASP开发了一套管理系统,现有一部分要与一个早期开发(VB4.0)MIS管理系统数据部分接口,就是从我的ASP系统输入数据到MIS管理系统中的DBF数据表中,请问如何实现。我用下面的方法和DBF文件连接,总是报“ODBC 驱动程序不支持所需的属性”的错误:
Dim conn,Driver,SourceType,DBPath
'建立Connection 对象
Set conn = Server.CreateObject("ADODB.Connection")
Driver="Driver={Microsoft Visual FoxPro Driver};"
SourceType = "SourceType=DBF;"
DBPath="SourceDB=c:\edis"
response.Write(DBPath)
'调用Open 方法打开数据库
conn.Open Driver & SourceType & DBPath
Set Rs = Server.CreateObject("ADODB.Recordset")
'打开DBF文件
Rs.Open("ZEROXT01.dbf"),conn,2,2
...全文
160 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
alan815 2003-09-13
  • 打赏
  • 举报
回复
呵呵,看来来晚了。恭喜楼主了,成功搞定!
yusiyin 2003-09-13
  • 打赏
  • 举报
回复
我自己解决了这个问题:方法如下
Set DBConn = Server.CreateObject("ADODB.Connection")
Driver = "Driver={Microsoft Visual FoxPro Driver};"
SourceType = "SourceType=DBF;"
DBPath = "SourceDB=" & Server.MapPath( "\" )
DBConn.Open Driver & SourceType & DBPath
Set Rs=Server.CreateObject("Adodb.RecordSet")
Rs.Open("SQL"),DBConn,2,2
用这样的方法可对DBF文件进行添加,修改删除,和操作SQL数据库一样
yusiyin 2003-09-12
  • 打赏
  • 举报
回复
我用DSN方法建立连接如下:
strDBdsn="DSN=sourceDbf;uid=;pwd="
Set objDBConn=Server.CreateObject("ADODB.Connection")
objDBConn.Open StrDBdsn
strSQL="Select * From zerowatt08"
Set Rs=server.CreateObject("Adodb.RecordSet")
Rs.Open(strSql),objDBConn,2,2
出现如下错误:

Microsoft OLE DB Provider for ODBC Drivers 错误 '80004005'

[Microsoft][ODBC dBase Driver] 外部表不是预期的格式。

到底是什么原因,请高手指教!一定给分!!!!
zl13 2003-09-12
  • 打赏
  • 举报
回复
哦,明白了!
首先:建一个用户dsn关联dbf文件
然后:建立数据查询任务
在转换里面选择字段名称
在查询里面生成sql语句
yusiyin 2003-09-12
  • 打赏
  • 举报
回复
zl13(琳) :谢谢你的回复,但我不太明白您的意思:
我不是要将DBF文件传送到MIS系统中,而是要通过网络在ASP系统中直接修改MIS系统的DBF数据表,如数据查询、插入、更新等!
你能再说明白一点吗?非常感谢!
zl13 2003-09-12
  • 打赏
  • 举报
回复
找到了,在sql server的数据转换服务的本地包里面,你只要新建一个包,然后选择两个连接就可以了
yzwxjun 2003-09-12
  • 打赏
  • 举报
回复
我也想知道这个原因。学习学习
yusiyin 2003-09-12
  • 打赏
  • 举报
回复
ttt2,能具体说一下如何使用吗?谢谢!
zl13 2003-09-12
  • 打赏
  • 举报
回复
我看过别人写程序的时候用的是sql server 2000,里面有一个sql server 2000数据互通的工具,配置好了就可以实现sql server和别的数据库文件互通,这样你在程序里就可以直接用sql语句访问他了,我贴段代码给你看一下吧,代码没有注释,具体怎么做我也不知道了。

Dim strGeneratorFile

Dim upload
Dim file
Dim formName
Dim formPath
Dim iCount
Dim strNewFileName
Dim strColSparator
Dim strErrMsg
Dim strClientFileName
Dim ExamPaper
Dim ScoreID
ScoreID = Replace(Replace(Replace(now,"-","")," ",""),":","")

strColSparator = vbTab
strNewFileName = "Score_" & ScoreID & ".DBF"

Set upload = new upload_5xsoft ''建立上传对象
ExamPaper = upload.form("paperid")
If upload.form("filepath")="" Then ''得到上传目录
Response.Write "请输入要上传至的目录!"
Set upload = Nothing
Response.End
Else
formPath=upload.form("filepath")
''在目录后加(/)
If right(formPath,1)<>"/" Then formPath = formPath & "/"
End If

For Each formName In upload.objFile ''列出所有上传了的文件
Set file = upload.file(formName) ''生成一个文件对象

strClientFileName = file.FileName

If UCase(Mid(strClientFileName,InStrRev(strClientFileName,"."))) <> ".DBF" Then
Response.Write "请选择正确的上传文件!"
Response.End
Else
If file.FileSize > 0 Then ''如果 FileSize > 0 说明有文件数据
file.SaveAs Server.mappath( formPath & strNewFileName) ''保存文件
Else
Response.Write "您上传的文件为空文件,请检查!"
Response.End
End If
End If
Set file = Nothing
Next

Set upload = Nothing ''删除此对象

Set objFSO = Server.CreateObject("Scripting.Filesystemobject")
Response.Write strNewFileName
objFSO.CopyFile Trim(Request.ServerVariables(4)) & "anaphase\DBF\" & strNewFileName, Trim(Request.ServerVariables(4)) & "anaphase\DTSImport\Score.dbf" , true

%>

<%
'--考试导入考试成绩
Dim ActionSql , ActionRs , AddSql
Dim DBFConn , DBFConnString
DBFConnString = "DSN=Sylvan_Score"
Set DBFConn = Server.CreateObject("ADODB.Connection")
DBFConn.open DBFConnString
ActionSql = "Select * From Score.DBF"
Set ActionRs = DBFConn.Execute(ActionSql)
If ActionRs.Eof and ActionRs.Bof then
Response.Write "No data"
Else
Do While Not ActionRs.Eof
AddSql = "Insert Into ScoreImport (ScoreID,PaperID,Flag,a,fam1,gname1,icnum2,country3,lg4,birth5,years6,field6,pos6," &_
"rgnum7,gcode8,sex9,edubak10,orgtype11,times12,when12,why12,lsco12,b,lissec,readsec,dat1,dat2) Values " &_
"(" & ScoreID & "," & ExamPaper & ",'" & ActionRs(0) & "','" & ActionRs(1) & "','" & ActionRs(2) & "'," &_
"'" & ActionRs(3) & "','" & ActionRs(4) & "','" & ActionRs(5) & "','" & ActionRs(6) & "'," &_
"'" & ActionRs(7) & "','" & ActionRs(8) & "','" & ActionRs(9) & "','" & ActionRs(10) & "'," &_
"'" & ActionRs(11) & "','" & ActionRs(12) & "','" & ActionRs(13) & "','" & ActionRs(14) & "'," &_
"'" & ActionRs(15) & "','" & ActionRs(16) & "','" & ActionRs(17) & "','" & ActionRs(18) & "'," &_
"'" & ActionRs(19) & "','" & ActionRs(20) & "','" & ActionRs(21) & "','" & ActionRs(22) & "'" &_
"," & ActionRs(23) & "," & ActionRs(24) & ")"
Conn.Execute(AddSql)
ActionRs.Movenext
Loop
End if
DBFConn.Close
Set ActionRs = Nothing
Set DBFConn = Nothing

Response.Redirect "export_score.asp?id=" & ScoreID


ttt2 2003-09-12
  • 打赏
  • 举报
回复
用数据源

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧