Office中国论坛/Access中国论坛

标题: 请帮我分析下错误怎么改正 [打印本页]

作者: badcatsysa    时间: 2006-12-8 18:23
标题: 请帮我分析下错误怎么改正
我想把d盘中的数据导入数据库,数据库名叫数据存储。能帮我看看怎么改下面的代码么?(老是出错,郁闷)


Public Function drsj()

    Dim Cnn As ADODB.Connection
    Dim ConnectString As String
    Dim Rs As New ADODB.Recordset
    Dim strsql As String

    ' 打开数据库
   
    Set Cnn = New ADODB.Connection
    ConnectString = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\数据库\数据存储.mdb;persist Security Info=False;"
   
                     
  
    Cnn.Open ConnectString
    Set Rs = New ADODB.Recordset
    Rs.AddNew
    Rs = Cnn.Execute"select * into 数据导入 from d:\数据"

    Rs.Update
    Cnn.Close  '*****************切断连接
    Set Cnn = Nothing
    End Function[em06][em06][em06]
作者: fan0217    时间: 2006-12-9 04:03
Public Function CopyRecord()
On Error GoTo Err_CopyRecord
    Dim connSour As New ADODB.Connection
    Dim connTar As New ADODB.Connection
    Dim rsSour As New ADODB.Recordset
    Dim rsTar As New ADODB.Recordset
    Dim strSourceSQL As String, strTargetSQL As String
    Dim i As Integer
    Dim strConnectString As String
   
    strConnectString = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\数据库\数据存储.mdb"
    connSour.Open strConnectString
    strSourceSQL = "select * from 源表"
    rsSour.Open strSourceSQL, connSour, adOpenKeyset, adLockOptimistic
   
    Set connTar = CurrentProject.Connection
    strTargetSQL = "select * from 目标表"
    rsTar.Open strTargetSQL, connTar, adOpenKeyset, adLockOptimistic
   
        Do Until rsSour.EOF
            rsTar.AddNew
                For i = 0 To rsSour.Fields.Count - 1
                    rsTar.Fields(i) = rsSour.Fields(i)
                Next
            rsTar.Update
            rsSour.MoveNext
        Loop
        
        rsSour.Close
        rsTar.Close
        connSour.Close
        connTar.Close
        Set connSour = Nothing
        Set connTar = Nothing

Exit_CopyRecord:
    Exit Function

Err_CopyRecord:
    Set connSour = Nothing
    Set connTar = Nothing
    MsgBox Err.Description
    Resume Exit_CopyRecord
End Function





欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3