请教:实现自动将数据逐条填充到表格。
    因为水平有限,自己天马行空了次。问题1,设置每秒接收一次,一分钟内,表中并不是60条记录,会少两条。问题2,在数据自动填充时,最后一条记录和倒数第二条记录之间相差为两秒。
    请能否提供一些相关的源码或是帮忙调试一下。感激!……
窗体:
Option Explicit
Dim mytime1
Private Sub Form_Load()
     mytime1 = Time
     DBCONNsql
     Dim sql
     Me.Adodc1.Visible = False
     sql = "select  username,password,shijian from system where shijian>='" & mytime1 & "'"
     Adodc1.ConnectionString = conn
     Me.Adodc1.RecordSource = sql
     Me.Adodc1.Refresh
     Set Me.DataGrid1.DataSource = Me.Adodc1.Recordset
     Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
     Dim i, rsNames
     Dim sql
     Dim mytime
     Me.Adodc1.Recordset.AddNew
     Me.Adodc1.Recordset("username") = 0
     Me.Adodc1.Recordset("password") = 2
     mytime = Time
     Me.Adodc1.Recordset("shijian") = Format(mytime, "h:m:s")
     sql = "select  username,password,shijian from system where shijian>='" & mytime1 & "'"
     Adodc1.ConnectionString = conn
     Me.Adodc1.RecordSource = sql
     Set Me.DataGrid1.DataSource = Me.Adodc1.Recordset
     Me.Adodc1.Recordset.Update
     Me.Adodc1.Refresh
End Sub
模块:
Option Explicit
Global Username As String  '登陆时的用户名称
Public conn As ADODB.Connection
Public Sub DBCONNsql()
    Dim connstr As String
    Set conn = New ADODB.Connection
    connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\jinyan.mdb;Persist Security Info=False"
    'ConnStr = "rovider=MSDASQL.1;Persist Security Info=False;Data Source=jy"
    conn.Open connstr
End Sub

解决方案 »

  1.   

    try:Timer1.Interval = 100Private Sub Timer1_Timer()
       if num < 10 then   '计数十次
           num=num+1
       else
    ...........
       end if 
    end sub
      

  2.   

    Private Sub Form_Load()
        Dim sql
        mytime1 = Time
        DBCONNsql
        Me.Adodc1.Visible = False
        sql = "select  username,password,shijian from system where shijian>='" & mytime1 & "'"
        Adodc1.ConnectionString = conn
        Me.Adodc1.RecordSource = sql
        Me.Adodc1.Refresh
        Set Me.DataGrid1.DataSource = Me.Adodc1.Recordset
        Timer1.Interval = 500
    End SubPrivate Sub Timer1_Timer()
        Dim i, rsNames
        Dim sql
        Dim mytime
        If Label1.Caption <> CStr(Time) Then
            Label1.Caption = Time$
            Me.Adodc1.Recordset.AddNew
            Me.Adodc1.Recordset("username") = 0
            Me.Adodc1.Recordset("password") = 2
            mytime = Time
            Me.Adodc1.Recordset("shijian") = Format(mytime, "h:m:s")
            sql = "select  username,password,shijian from system where shijian>='" & mytime1 & "'"
            Adodc1.ConnectionString = conn
            Me.Adodc1.RecordSource = sql
            Set Me.DataGrid1.DataSource = Me.Adodc1.Recordset
            Me.Adodc1.Recordset.Update
            Me.Adodc1.Refresh
        End If
    End Sub