设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 2049|回复: 1
打印 上一主题 下一主题

[ADO/DAO] 使用ADO 操作未打开表的新记录!

[复制链接]
跳转到指定楼层
1#
发表于 2012-6-13 11:42:41 | 只看该作者 回帖奖励 |正序浏览 |阅读模式

Public Sub AddNewRecord()

Dim rs As New ADODB.Recordset

rs.Open "Contacts", CurrentProject.Connection, , adLockOptimistic

With rs

    .AddNew

    ![fieldsArray] = "55"

    ![valuesArray] = "66"

    .Update

End With

rs.Update

rs.Close

Set rs = Nothing

End Sub

新增、修改以及堆栈记录 access ado


新增:
Public Sub AddNewRecord(aa As String, bb As String)

Dim rs As New ADODB.Recordset

rs.Open "Contacts", CurrentProject.Connection, , adLockOptimistic

With rs

    .AddNew

    ![fieldsArray] = aa & bb

    ![valuesArray] = Date

    .Update

End With

rs.Update

rs.Close

Set rs = Nothing

End Sub



Public Sub hello()

'Call AddNewRecord("hello", "朝鲜")

Call ModifyRecord("lol", " 旭")

End Sub

修改:

Public Sub ModifyRecord(cc As String, dd As String)

Dim rs As New ADODB.Recordset

rs.Open "select * from Contacts where ID = 45", CurrentProject.Connection, , adLockOptimistic

rs![fieldsArray] = cc

rs![valuesArray] = cc & dd

rs.Update

rs.Close

Set rs = Nothing

End Sub

堆栈:



Public Sub roll()

Dim rs As New ADODB.Recordset

Dim aa As String

aa = "哈哈哈"

rs.Open "select * from Contacts ", CurrentProject.Connection, , adLockOptimistic

While rs.EOF = False

aa = aa & rs!fieldsArray

rs.MoveNext

Wend

MsgBox (aa)

rs.Close

Set rs = Nothing

End Sub
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2013-1-9 17:29:07 | 只看该作者
要是有个实例就清楚多了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-16 15:14 , Processed in 0.069826 second(s), 26 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表