把查找的数据动态添加数据库里的问题,按左右方向列方式添加的问题。
  每次的数据按行添加数据,查找次数与字段添加位置相等。  

解决方案 »

  1.   

    没看懂你的意思。天狼工作室
    http://www.j2soft.cn/
      

  2.   

    哈哈,问了半天才明白他要做什么,不问是看不明白的Private Sub Command1_Click()
        Dim cn As New ADODB.Connection
        Dim rs As New ADODB.Recordset
        Dim i As Integer
        Dim j As Integer
        Dim strTemp As String
        Dim intCount As Integer
        Dim m As Integer
        Dim intRow As Integer    cn.CursorLocation = adUseClient
        cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\mydb.mdb;Persist Security Info=False"
        
        rs.Open "select * from mytable", cn, adOpenStatic, adLockOptimistic
        
        If rs.RecordCount > 0 Then
            While Not rs.EOF
                For i = rs.Fields.Count - 1 To 0 Step -1
                    If rs.Fields(i) <> Null Or rs.Fields(i) <> "" Then
                        If i > intCount Then
                            intCount = i
                        End If
                        Exit For
                    End If
                Next i
                rs.MoveNext
            Wend
        End If
        
        With MSFlexGrid1
            .Col = Text2.Text
            
            For j = 1 To .Rows - 1
                .Row = j
                If .Text = Text1.Text Then
                    
                    .Row = j + 1
                    If .Text <> "" Then
                        intRow = 0
                        intCount = intCount + 1
                        
                        If Text3.Text > rs.RecordCount Then
                            For i = rs.RecordCount + 1 To Text3.Text - 1
                                rs.AddNew
                                rs.Fields(0) = i
                                rs.Update
                            Next i
                        Else
                            rs.MoveFirst
                            For i = 1 To Text3.Text - 1
                                rs.MoveNext
                            Next i
                        End If
                        
                        For m = j + 1 To .Rows - 1
                            .Row = m
                            If .Text <> "" Then
                                intRow = intRow + 1
                                
                                If rs.EOF Then
                                    rs.AddNew
                                    rs.Fields(0) = Text3.Text - 1 + intRow
                                    rs.Fields(intCount) = .Text
                                    rs.Update
                                Else
            '                        rs.MoveNext
                                    rs.Fields(intCount) = .Text
                                    rs.Update
                                End If
                                
                                rs.MoveNext
                            End If
                        Next m
                    End If
                End If
            Next j
            
        End With
        
    '    rs.Save
        
        rs.Close
        cn.Close
        Set rs = Nothing
        Set cn = NothingEnd SubPrivate Sub Form_Load()
        Dim TextLine
        Dim strFileName As String
        Dim a() As String
        Dim i As Integer
        Dim j As Integer
        With MSFlexGrid1
            .Rows = 20
            .Cols = 6        strFileName = App.Path & "\testdata.txt"        Open strFileName For Input As #1 ' 打开文件。        Do While Not EOF(1) ' 循环至文件尾。
                Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。
                i = i + 1
                .Row = i
                For j = 1 To Len(TextLine)
                    .Col = j
                    .Text = Mid(TextLine, j, 1)
                Next j        Loop        Close #1 ' 关闭文件。
        End WithEnd Sub