2010-05-12 87 views
0

我使用Excel来连接到MySQL数据库:如何使用ADODB.Recordset更新数据库?

Dim dpath, atime, rtime, lcalib, aname, rname, bstate, instrument As String 
Dim rs As ADODB.Recordset 
    Set rs = New ADODB.Recordset 
    ConnectDB 
    With wsBooks 
      rs.Open "batchinfo", oConn, adOpenKeyset, adLockOptimistic, adCmdTable 


    Worksheets.Item("Report 1").Select 
    dpath = Trim(Range("B2").Text) 
    atime = Trim(Range("B3").Text) 
    rtime = Trim(Range("B4").Text) 
    lcalib = Trim(Range("B5").Text) 
    aname = Trim(Range("B6").Text) 
    rname = Trim(Range("B7").Text) 
    bstate = Trim(Range("B8").Text) 

     ' instrument = GetInstrFromXML(wbBook.FullName) 

    With rs 
     .AddNew ' create a new record 
     ' add values to each field in the record 
     .Fields("datapath") = dpath 
     .Fields("analysistime") = atime 
     .Fields("reporttime") = rtime 
     .Fields("lastcalib") = lcalib 
     .Fields("analystname") = aname 
     .Fields("reportname") = rname 
     .Fields("batchstate") = "bstate" 
     .Fields("instrument") = "NA" 
     .Update 

' stores the new record 
    End With 

什么下一步?

我该如何做一个rs.execute?

回答

1

应该rs.Update()做到这一点吗?或者你可以调用rs.Requery(),它更新和刷新记录集。

相关问题