急寻帮助! txt文件导入ACCESS中以及MSFlexGrid数据导出到txt文件中????
我自己写了下,txt文件数据比较多,执行效率低下
请教大家有没好的方法

解决方案 »

  1.   

    Private Sub Command1_Click()
        Screen.MousePointer = vbHourglass
        Dim intFreeNumber As Integer
        Dim Conn As ADODB.Connection
        Dim rs As ADODB.Recordset
        Dim rsArray() As String, fdArray() As String
        Dim i As Long, j As Long
        intFreeNumber = FreeFile()    Open App.Path & "\MCZ-2004-08-21-灯丝电压(0001)X-DJ.txt" For Binary As #intFreeNumber
        Do While Not EOF(intFreeNumber)
          strTemp = Input(intFreeNumber, #intFreeNumber)
          strfile = strfile & strTemp
        Loop
        Close #intFreeNumber
        Set Conn = New ADODB.Connection
        Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\MC.mdb;Persist Security Info=False"
        Set rs = New ADODB.Recordset
        rs.CursorLocation = adUseClient
    '''    rs.Open "select * from 灯丝电压 where 时间=''", Conn, adOpenStatic, adLockBatchOptimistic, 1
        rs.Open "select * from 灯丝电压 order by 时间", Conn, adOpenStatic, adLockBatchOptimistic, 1
        rsArray = Split(strfile, vbCrLf)
        For i = 0 To UBound(rsArray)
            fdArray = Split(rsArray(i), ",")
            'For j = 0 To 1
                rs.AddNew
                rs(0).Value = Trim(fdArray(0))
                rs(1).Value = Trim(fdArray(1))
            'Next j
        Next i
        rs.UpdateBatch
        Set rs = Nothing
        
        Screen.MousePointer = vbDefault
        MsgBox CStr(i) & "行记录从文本文件中导入数据库!"
        Exit Sub
    End Sub'OutDataToText
    '将MsFlexGrid控件中显示的内容输出到文本文件
    Public Sub OutDataToText(Flex As MSFlexGrid) 
    Dim s As String
    Dim i As Integer
    Dim j As Integer
    Dim k As Integer
    Dim strTemp As String
    On Error GoTo Ert
    Me.MousePointer = 11
    On Error Resume Next
    DoEvents
    Dim FileNum As Integer
    FileNum = FreeFile
    Open "d:\aa.txt" For Output As #FileNum
    With Flex
    k = .Rows
    For i = 0 To k - 1
    strTemp = ""
    For j = 0 To .Cols - 1
    DoEvents
    strTemp = strTemp & .TextMatrix(i, j) & ","
    Next j
    Print #FileNum, Left(strTemp, Len(strTemp) - 1)
    Next i
    End With
    Close #FileNum
    Me.MousePointer = 0
    MsgBox "导出成功"
    Ert:
    MsgBox Err.Description
    Me.MousePointer = 0
    End Sub
      

  2.   

    顶.我还有个帖子没人理会.55555555555555555555555郁闷到极点,都2个月了.没办法结贴子...................http://community.csdn.net/Expert/topic/5027/5027342.xml?temp=4.055202E-03