ADODB.Field为何不能用?

Zhayinghua 2003-10-21 01:15:42
我定义
Dim fld AS New ADODB.Field
为何运行时提示
Compile error:
Invalid use of New keyword

除了Add-in ADO之外,还需要进行额外的设置么?请各位帮帮忙!一定多送分
...全文
126 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Zhayinghua 2003-10-22
  • 打赏
  • 举报
回复
为何没人回答我的问题啊? 大侠们帮帮忙吧!!!
Zhayinghua 2003-10-21
  • 打赏
  • 举报
回复
这个程序是ADO 2.7的例子,我是想按照它的方式定义一个Field,可报错,不知道是何原因?
Lucky527 2003-10-21
  • 打赏
  • 举报
回复
楼主,你的程序完全正确,运行正常啊!!

SUB FORM_LOAD()
CALL ValueX()
END SUB
Lucky527 2003-10-21
  • 打赏
  • 举报
回复
我查过,adodb.field 的确正确,就是怎么用的问题
dim rs as adodb.recordset
dim rs as adodb.field
Set flds as rs.fields
For Each fld In flds

上面的代码里也有
For Each fld In rstEmployees.fields
Zhayinghua 2003-10-21
  • 打赏
  • 举报
回复
以下代码是从ADO 2.7的帮助上摘录的:

'BeginValueVB
Public Sub ValueX()

'To integrate this code
'replace the data source and initial catalog values
'in the connection string

' connection and recordset variables
Dim rstEmployees As ADODB.Recordset
Dim Cnxn As ADODB.Connection
Dim strCnxn As String
Dim strSQLEmployees As String
' field property variables
Dim fld As ADODB.Field
Dim prp As ADODB.Property

' Open connection
Set Cnxn = New ADODB.Connection
strCnxn = "Provider=sqloledb;Data Source=MyServer;Initial Catalog=Pubs;User Id=sa;Password=; "
Cnxn.Open strCnxn

' Open recordset with data from Employees table
Set rstEmployees = New ADODB.Recordset
strSQLEmployees = "employee"
rstEmployees.Open strSQLEmployees, Cnxn, , , adCmdTable
'rstEmployees.Open strSQLEmployees, Cnxn, adOpenStatic, adLockReadOnly, adCmdTable
' the above two lines of code are identical

Debug.Print "Field values in rstEmployees"

' Enumerate the Fields collection of the Employees table
For Each fld In rstEmployees.fields
' Because Value is the default property of a
' Field object, the use of the actual keyword
' here is optional.
Debug.Print " " & fld.Name & " = " & fld.Value
Next fld

Debug.Print "Property values in rstEmployees"

' Enumerate the Properties collection of the Recordset object
For Each prp In rstEmployees.Properties
Debug.Print " " & prp.Name & " = " & prp.Value
' because Value is the default property of a Property object
' use of the actual Value keyword is optional
Next prp

' clean up
rstEmployees.Close
Cnxn.Close
Set rstEmployees = Nothing
Set Cnxn = Nothing

End Sub
'EndValueVB

为何它就可以用呢?请各位解释一下,谢谢!
射天狼 2003-10-21
  • 打赏
  • 举报
回复
楼上几位说的没错~~
守城小轩 2003-10-21
  • 打赏
  • 举报
回复
Dim fld AS New ADODB.Field
错误 adodb没有field
Dim rs As New ADODB.Recordset
li_ping 2003-10-21
  • 打赏
  • 举报
回复
不需要再做其他的设置了,可能是其他的问题吧,可以把你的程序贴出来看一下.
Lucky527 2003-10-21
  • 打赏
  • 举报
回复
ADO很好用的,我习惯用它

我平时这么用

dim fld as new ADODB.recordset
fld.field ...
.
.
.

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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