用Dao如何访问odbc数据源?

xfflean 2001-11-28 10:29:51
小弟最近学了dao,但只会连接mdb数据库文件
odbc数据源的试了好多次都不成,又没有msdn
所以只好问问各位大哥,
最好能给上一段代码.
还有tabledef对象到底是怎么回事?
我:
dim a as database
dim b as tabeldef
set a=opendatabase("d:\a.mdb")
for each tabeldef in a.tabeldefs
msgbox tabeldef.recordcount
next
d:\a.mdb中只有两个表,为啥运行时出现了5次msgbox.
...全文
128 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
sonicdater 2001-12-06
  • 打赏
  • 举报
回复
对于 tabledef 对象。
你 可以把它 看作是个 数据库 中的 表。

tabledef对象 有它 自己的 属性和 方法。 你把这些方法 看作 是对这个 表的 操作。
sonicdater 2001-12-06
  • 打赏
  • 举报
回复
Sub OpenDatabaseX()

Dim wrkJet As Workspace
Dim dbsNorthwind As Database
Dim dbsPubs As Database
Dim dbsPubs2 As Database
Dim dbsLoop As Database
Dim prpLoop As Property

' Create Microsoft Jet Workspace object.
Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)

' Open Database object from saved Microsoft Jet database
' for exclusive use.
MsgBox "Opening Northwind..."
Set dbsNorthwind = wrkJet.OpenDatabase("Northwind.mdb", True)

' Open read-only Database object based on information in
' the connect string.
MsgBox "Opening pubs..."
Set dbsPubs = wrkJet.OpenDatabase("Publishers", _
dbDriverNoPrompt, True, _
"ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers")

' Open read-only Database object by entering only the
' missing information in the ODBC Driver Manager dialog
' box.
MsgBox "Opening second copy of pubs..."
Set dbsPubs2 = wrkJet.OpenDatabase("Publishers", _
dbDriverCompleteRequired, True, _
"ODBC;DATABASE=pubs;DSN=Publishers;")

' Enumerate the Databases collection.
For Each dbsLoop In wrkJet.Databases
Debug.Print "Database properties for " & _
dbsLoop.Name & ":"

On Error Resume Next
' Enumerate the Properties collection of each Database
' object.
For Each prpLoop In dbsLoop.Properties
If prpLoop.Name = "Connection" Then
' Property actually returns a Connection object.
Debug.Print " Connection[.Name] = " & _
dbsLoop.Connection.Name
Else
Debug.Print " " & prpLoop.Name & " = " & _
prpLoop
End If
Next prpLoop
On Error GoTo 0

Next dbsLoop

dbsNorthwind.Close
dbsPubs.Close
dbsPubs2.Close
wrkJet.Close

End Sub
rushing 2001-12-06
  • 打赏
  • 举报
回复
帮你u p一下
xfflean 2001-11-28
  • 打赏
  • 举报
回复
没人在??????????????????????????
xfflean 2001-11-28
  • 打赏
  • 举报
回复
UP!
xxlroad 2001-11-28
  • 打赏
  • 举报
回复
xfflean 2001-11-28
  • 打赏
  • 举报
回复
?????????????????
xfflean 2001-11-28
  • 打赏
  • 举报
回复
高手在哪啊????
急啊!!!!!!!!!!!!!
谁帮忙Up也好~
xfflean 2001-11-28
  • 打赏
  • 举报
回复
????????
UP!!!!!!!!!!!!!

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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