- ©«¤l
- 117
- ¥DÃD
- 34
- ºëµØ
- 0
- ¿n¤À
- 155
- ÂI¦W
- 0
- §@·~¨t²Î
- windows XP
- ³nÅ骩¥»
- OFFICE 2010
- ¾\ŪÅv
- 20
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2010-5-19
- ³Ì«áµn¿ý
- 2024-8-29
|
ADO°ÝÃD
³Ìªñ¶}©l¾Ç²ß¨Ï¥ÎADO³sµ²Access¥\¯à, ¦b³o·Q½Ð±Ð¦U¦ì«e½ú¤@¨Ç°ÝÃD, ÁÂÁÂ~
1. ¦b¬õ¦r³¡¥÷, ¦pªG¨S¦³where.... ¥\¯à¬O¥¿±`ªº, ¥[¤Fwhere´N·|¥X²{2147217913 Automationªº¿ù»~
¤£ª¾¹D³o³¡¥÷¸Ó«ç»ò±ø§ï!?
2. CursorType:=adOpenDynamic, LockType:=adLockOptimistic ³o2¥y¦b¨ä¥LªºÀ³¥Î·|¦³¤£¦P¶Ü?(¥Ø«e¦³¬Ý¨ì¥t¤@ºØCursorType:=adOpenStatic)
Sub ADO()
Dim strDB As String, strSQL As String
Dim i As Long, n As Long, lFieldCount As Long
Dim rng As Range
Dim adoRecSet As New ADODB.Recordset
Dim connDB As New ADODB.Connection
strDB = "C:\Users\Color\Desktop\Database1.accdb"
connDB.Open ConnectionString:="Provider = Microsoft.ACE.OLEDB.12.0; data source=" & strDB
Dim ws As Worksheet
Set ws = ActiveWorkbook.Sheets("sheet1")
Set adoRecSet = New ADODB.Recordset
strSQL = "SELECT Code FROM Stock WHERE Price > 100"
adoRecSet.Open Source:=strSQL, ActiveConnection:=connDB, CursorType:=adOpenDynamic, LockType:=adLockOptimistic
Set rng = ws.Range("A1")
lFieldCount = adoRecSet.Fields.Count
For i = 0 To lFieldCount - 1
rng.Offset(0, i).Value = adoRecSet.Fields(i).Name
Next i
rng.Offset(1, 0).CopyFromRecordset adoRecSet
Range(ws.Columns(1), ws.Columns(lFieldCount)).AutoFit
adoRecSet.Close
connDB.Close
Set adoRecSet = Nothing
Set connDB = Nothing
End Sub
ACCESS¸ê®Æ®w³¡¥÷¶È¦³3Äæ°µ´ú¸Õ
Code Price Volume
123 99 100
456 456 200 |
|