ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

°õ¦æ¥X¿ù~§ä¤£¨ì¸ê®Æ©Î¸ê®Æ«¬ºA¿ù»~

°õ¦æ¥X¿ù~§ä¤£¨ì¸ê®Æ©Î¸ê®Æ«¬ºA¿ù»~

¥»©«³Ì«á¥Ñ shenfu ©ó 2010-6-27 18:52 ½s¿è

Sub PopulateOneField()
    Dim cnn As ADODB.Connection
    Dim MyConn
    Dim rst As ADODB.Recordset
    Dim i As Long, j As Long
    Dim Rw As Long
    Dim sSQL As String
    Dim sID As Long
  
    Sheets("sheet1").Activate
    Rw = Range("A65535").End(xlUp).Row

    Set cnn = New ADODB.Connection
    MyConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=D:\db.mdb;"


    With cnn
        .Provider = "Microsoft.Jet.OLEDB.4.0"
        .Open MyConn
    End With

    Set rst = New ADODB.Recordset
    rst.CursorLocation = adUseServer
   

    For i = 2 To 100
        sID = Cells(i, 1).Value
        sSQL = "select * from abc where abc.ID = " & sID
        
     
        rst.Open Source:=sSQL, ActiveConnection:=cnn, _
                 CursorType:=adOpenKeyset, LockType:=adLockOptimistic
         

            rst(Cells(1, 2).Value) = Cells(i, 2).Value
            rst(Cells(1, 3).Value) = Cells(i, 3).Value
            rst(Cells(1, 4).Value) = Cells(i, 4).Value
            rst(Cells(1, 5).Value) = Cells(i, 5).Value
           
            
            rst.Update
            
   
        rst.Close
    Next i


    cnn.Close
    Set rst = Nothing
    Set cnn = Nothing

End Sub

¥H¤Wµ{¦¡°õ¦æ·|¥X¿ù
·Ç«h¹Bºâ¦¡ªº¸ê®ÆÃþ«¬¤£²Å¦X
¥i¬O§Ú³£§âid«¬ºA§ï¬°¤å¦r©Î¥þ§ï¼Æ¦r³£¨S¥Î¤]..
½Ð°Ý¦³¦ó¿ìªk¶Ü
§Úªºid³£¬Oaccess¤¤¦³ªº
¦Ó¦pªG§ï¦¨ ' " & sID & " '
¤]¬O·|¥X²{
=>¥i¯à¬O bof ©Î eof ªº­È¬° true ©Î¥Ø«eªº¸ê®Æ¿ý¤w³Q§R°£
50 ¦r¸`¥H¤º
¤£¤ä«ù¦Û©w¸q Discuz! ¥N½X

¥»©«³Ì«á¥Ñ Min ©ó 2010-6-27 21:35 ½s¿è

¸Õ¸Õ¬Ý
sSQL = "select * from abc where abc.ID = '" & sID & "'"
­Y¬O§Ú¦^µª¡A¨Ï±zº¡·N¡A½Ð±zÅý§Úª¾¹D¡I                  
­Y¬O§Úªº¦^ÂСA±z¤´¦³¨ä¥L¨£¸Ñ¡A¤]½Ð±z¤£¶Þ«ü±Ð¡I

TOP

        ÀR«ä¦Û¦b : ¤@­Ó¤H¤£©È¿ù¡A´N©È¤£§ï¹L¡A§ï¹L¨Ã¤£Ãø¡C
ªð¦^¦Cªí ¤W¤@¥DÃD