设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

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

[模块/函数] 求助!用ADO绑定窗体记录源后,断开,后怎么在联上。

[复制链接]
跳转到指定楼层
1#
发表于 2012-3-17 02:09:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
用ADO绑定窗体记录源后,断开,后怎么在联上。
如题:
Private Function ADOBatchRst(frm As Form, RecSource As String) As Integer
    Dim rs As New ADODB.Recordset
    With rs
        .CursorLocation = adUseClient
        .Open RecSource, sqlcon adOpenStatic, adLockBatchOptimistic
       Set .ActiveConnection = Nothing    ' 断开连接    End With
    Set frm.Recordset = rs
'    ADOBatchRst = rs.RecordCount
    Set rs = Nothing
End Function
以上函数是小宝版主的。
ADOBatchRst me.子窗体.form,"表1"


在对子窗体的数据进行,新增,修改,册除后,
怎么  链接上  并  对数据进行保存(批量更新)UpdateBatch


谢谢!!!!!!!!!!!!
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2012-3-17 11:30:36 | 只看该作者
一就是 这样的!
3#
发表于 2012-3-21 16:20:02 | 只看该作者
抄段帮助 给你:
Open 和 Close 方法范例 (VB)
本范例在已打开的 Recordset 和 Connection 对象上使用 Open 和 Close 方法。

'BeginOpenVB

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

Public Sub OpenX()
    On Error GoTo ErrorHandler

    Dim Cnxn As ADODB.Connection
    Dim rstEmployees As ADODB.Recordset
    Dim strCnxn As String
    Dim strSQLEmployees As String
    Dim varDate As Variant
   
    ' Open connection
    strCnxn = "Provider='sqloledb';Data Source='MySqlServer';" & _
        "Initial Catalog='Pubs';Integrated Security='SSPI';"
    Set Cnxn = New ADODB.Connection
    Cnxn.Open strCnxn
   
    ' Open employee table
    Set rstEmployees = New ADODB.Recordset
    strSQLEmployees = "employee"
    rstEmployees.Open strSQLEmployees, Cnxn, adOpenKeyset, adLockOptimistic, adCmdTable
   
    ' Assign the first employee record's hire date
    ' to a variable, then change the hire date
    varDate = rstEmployees!hire_date
    Debug.Print "Original data"
    Debug.Print "  Name - Hire Date"
    Debug.Print "  " & rstEmployees!fname & " " & _
        rstEmployees!lname & " - " & rstEmployees!hire_date
    rstEmployees!hire_date = #1/1/1900#
    rstEmployees.Update
    Debug.Print "Changed data"
    Debug.Print "  Name - Hire Date"
    Debug.Print "  " & rstEmployees!fname & " " & _
        rstEmployees!lname & " - " & rstEmployees!hire_date
   
    ' Requery Recordset and reset the hire date
    rstEmployees.Requery
    rstEmployees!hire_date = varDate
    rstEmployees.Update
    Debug.Print "Data after reset"
    Debug.Print "  Name - Hire Date"
    Debug.Print "  " & rstEmployees!fname & " " & _
       rstEmployees!lname & " - " & rstEmployees!hire_date

    ' clean up
    rstEmployees.Close
    Cnxn.Close
    Set rstEmployees = Nothing
    Set Cnxn = Nothing
    Exit Sub
   
ErrorHandler:
    ' clean up
    If Not rstEmployees Is Nothing Then
        If rstEmployees.State = adStateOpen Then rstEmployees.Close
    End If
    Set rstEmployees = Nothing
   
    If Not Cnxn Is Nothing Then
        If Cnxn.State = adStateOpen Then Cnxn.Close
    End If
    Set Cnxn = Nothing
   
    If Err <> 0 Then
        MsgBox Err.Source & "-->" & Err.Description, , "Error"
    End If
End Sub
'EndOpenVB
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-3 16:47 , Processed in 0.096314 second(s), 26 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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