1.将收到数据时时间记录到数据库中
2.sql数据库 acess数据库 记录方法一样吗?
3.能不能给个例子
谢了!

解决方案 »

  1.   

    在写数据记录时将系统时间以时间格式或字符格式写进数据库.
    Private Sub Timer2_Timer()
        If Label1.Caption <> CStr(Time$) Then
            Label1.Caption = Time$
            sum_mdb = sum_mdb + 1
            If Mid(Time$, 7, 2) = "00" Then '每分钟记录一组数据
                Adodc1.Recordset.AddNew
                Adodc1.Recordset(0) = Mid(Date$, 3, 2) & Mid(Date$, 6, 2) & Mid(Date$, 9, 2) & Mid(Time$, 1, 2) & Mid(Time$, 4, 2)         '记录时间
                Adodc1.Recordset(1) = record_jm(0)  '记录数据
                Adodc1.Recordset(2) = record_jm(1)  '记录数据
                Adodc1.Recordset(3) = record_jm(2)  '记录数据
                '.....
            End If
        End If
    End SubPrivate Sub Form_Load()
        Timer1.Interval = 500
    End Sub
      

  2.   

    那就在接收到正确数据时执行写数据记录时用上述部分代码
               Adodc1.Recordset.AddNew
               Adodc1.Recordset(0) = Mid(Date$, 3, 2) & Mid(Date$, 6, 2) & Mid(Date$, 9, 2) & Mid(Time$, 1, 2) & Mid(Time$, 4, 2)         '记录时间
                Adodc1.Recordset(1) = record_jm(0)  '记录数据
                Adodc1.Recordset(2) = record_jm(1)  '记录数据
                Adodc1.Recordset(3) = record_jm(2)  '记录数据
                '.....
      

  3.   

    SQL SERVER时间用''(单引号)号引起来,
    ACCESS时间用##(井字号)引起,
    连接方式也不有同,我这里连接ACCESS
    Private Sub Form_Load()
        Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\" & _
                                  "Administrator\My Documents\11.mdb;Persist Security Info=False"
        Adodc1.CursorLocation = adUseClient
        Adodc1.CommandType = adCmdText
        Adodc1.RecordSource = "select * from itb1"
        Adodc1.Refresh
        Set DataGrid1.DataSource = Adodc1
        iniMscomm
    End SubPrivate Sub iniMscomm()
       On Error Resume Next
    '=====-----初始化通信串口-----=====
       MSComm1.CommPort = 1
       MSComm1.Settings = "9600,N,8,1"
       MSComm1.PortOpen = True
       MSComm1.RThreshold = 1
       MSComm1.InputLen = 0
       MSComm1.InputMode = comInputModeBinary
       MSComm1.RTSEnable = True
       MSComm1.InBufferCount = 0End Sub
    Private Sub MSComm1_OnComm()
    '=====>等待下位机触发各种事件<==========
      
      Dim t1 As Long
      t1 = Timer
      Select Case MSComm1.CommEvent
         Case comEvReceive '收到 RThreshold定义的字符数1字节
              MSComm1.RThreshold = 0
              Do
                 DoEvents
              Loop While Timer - t1 < 1
              
              Call Receive '调用接收过程处理数据
              MSComm1.RThreshold = 1
           End Select
           
    End SubPrivate Sub Receive()
       sql = "INSERT INTO itb1(a) VALUES (#" & Now & "#)"
       Adodc1.Recordset.ActiveConnection.Execute sql
       Adodc1.Refresh   
    End Sub