Dim rs As Recordset
Set rs = New ADODB.Recordset
rs.Open "select * from info", strconn + App.Path + "\novels.mdb", 3, 3
rs.AddNew
rs("title") = Title
rs("classify") = classify
rs("publisher") = publisher
rs("pdate") = CDate(pdate)
rs("edate") = CDate(edate)
rs("lcontent").AppendChunk (lcontent)
rs.Update
rs.Close
Set rs = Nothing
字段设置成二进制或long text字段。

解决方案 »

  1.   

    能用access做这个文本文件
    的联结吗?
    如果能的话
    应该可以直接导入了
    不用VB编
      

  2.   

    jet engine(ADO/DAO)可以直接打开文本文件数据库,但有格式要求。
      

  3.   

    文本也可以用ADO 连接的,但是必须是按一定的格式保存的才可以,用两个连接就可以用 Insert into 语句写入了。
      

  4.   

    文本里含有数据!数据是从ORACLE中导出的文本文件!
    现在关键是如何连接文本文件?
    请大家指教!
      

  5.   

    从ORACLE中导出的文本文件,应该使用Access的数据导入功能可以直接导入的啊。不需要编程的。
      

  6.   


      是不是程序需求?
      如果是为了搭建数据库,直接用ACCESS导入就可以了。  如果是程序需要,可以在ODBC设置 microsoft text Driver驱动的dsn,
      然后设置ado控件的data source为这个dsn.  
      

  7.   

    呵呵,这样啊。以下是一个从文本倒入数据库的例子,你可以参考。程序要引用MADO2.0libary 和Microsoft scripting runtime。如果有用特殊字符标志的字段,用split分解成数组后再倒入:
    Option Explicit
    Private Sub cmdBrowse_Click()
        cmdlg.FileName = txtFile.Text
        cmdlg.ShowOpen
        txtFile.Text = cmdlg.FileName
        SaveSetting "VBdata", "LawCenter", "Filename", txtFile.Text
    End SubPrivate Sub cmdStart_Click()
        Dim Fs As New FileSystemObject
        Dim fdPath As String
        Dim fd As Folder
        Dim fc As Files
        Dim fl As File
        Dim ts As TextStream
        Dim strLine As String
        Dim strField(1 To 11) As Variant
        Dim iLoop As Integer
        
        Dim db As Connection
        Dim adoPrimaryRS As Recordset
        Dim i As Long
        
        cmdStart.Enabled = False
        txtFile.Enabled = False
        cmdBrowse.Enabled = False
        Me.MousePointer = vbHourglass
        
        Set db = New Connection
        db.CursorLocation = adUseServer
       db.Open "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=******"
        Set adoPrimaryRS = New Recordset    
        adoPrimaryRS.Open "select isnull(max(pkNo),0) + 1 from LawCenter", db, adOpenForwardOnly, adLockReadOnly
        i = adoPrimaryRS.Fields(0)
        adoPrimaryRS.Close
        
        adoPrimaryRS.Open "select * from LawCenter", db, adOpenStatic, adLockOptimistic       
        fdPath = Left(txtFile, InStrRev(txtFile.Text, "\") - 1) 'Len(txtFile.Text) -
        Set fd = Fs.GetFolder(fdPath)
        Set fc = fd.Files
        pgbLaws.Min = 0
        pgbLaws.Max = fd.Files.Count
        pgbLaws.Value = 0
        
        'On Error GoTo ErrLine
        
        For Each fl In fc
            'Debug.Print fl.Path
    Restart: Set ts = Fs.OpenTextFile(fl.Path, ForReading, False)
            Debug.Print fl.Path
            With ts
                For iLoop = 1 To 10
                    strField(iLoop) = Trim(.ReadLine)
                    If strField(iLoop) = vbNullString Then
                        strField(iLoop) = Null
                    End If
                    Debug.Print strField(iLoop)
                Next iLoop
                If IsNull(strField(1)) Or IsNull(strField(3)) Or IsNull(strField(7)) Then
                    Debug.Print fl.Path
                    Stop
                End If
                strField(11) = vbNullString
                Do Until .AtEndOfStream
                    strField(11) = strField(11) & .ReadLine & "<br>"
                Loop
                
                strField(11) = Replace(strField(11), "  ", " ")
                
                If Not IsNull(strField(6)) Then
                    strField(6) = Left(strField(6), 4) & "-" & Mid(strField(6), 6, 2) & "-" & Mid(strField(6), 9, 2)
                    Debug.Print strField(6)
                    strField(6) = CDate(strField(6))
                End If
                If Not IsNull(strField(7)) Then
                    strField(7) = Left(strField(7), 4) & "-" & Mid(strField(7), 6, 2) & "-" & Mid(strField(7), 9, 2)
                    Debug.Print strField(7)
                    strField(7) = CDate(strField(7))
                End If
                If strField(8) = "有效" Then
                    strField(8) = True
                Else
                    strField(8) = False
                    Debug.Print fl.Path
                    Stop
                End If
                
                Debug.Print i
                    With adoPrimaryRS
                       .AddNew
                       .Fields(0) = i
                       For iLoop = 1 To 11
                            .Fields(iLoop) = strField(iLoop)
                       Next iLoop
                       .Update
                       'On Error GoTo 0
                        DoEvents
                    End With
                    i = i + 1
    skip:        .Close
                DoEvents
                pgbLaws.Value = pgbLaws.Value + 1
            End With
            Next
        adoPrimaryRS.Close
        db.Close
        
        cmdStart.Enabled = True
        txtFile.Enabled = True
        cmdBrowse.Enabled = True
        Me.MousePointer = vbDefault
        
        Exit Sub
    ErrLine:
        Debug.Print fl.Path
        Debug.Print Err.Description
        Stop
        adoPrimaryRS.CancelUpdate
        Err.Clear
        ts.Close
        GoTo Restart
    '    If Err.Number = -2147217887 Or Err.Number = -2147467259 Then
    '        adoPrimaryRS.CancelUpdate
    '        Debug.Print "Error"
    '        ErrCount = ErrCount + 1
    '        Resume Next
    '    Else
    '        Stop
    '        adoPrimaryRS.CancelUpdate
    '        Resume Next
    '    End If
    End Sub
    Private Sub Form_Load()
        txtFile.Text = GetSetting("VBdata", "LawCenter", "Filename")
    End Sub
      

  8.   

    因为是需要这样的程序解决这个问题?
    我原来用FSO!不知道是否有更好的方法?