2008/03/13

AcceessのADOでの繋ぎ方

再びAccessでのお仕事が入ってきそうなのでリハビリ。まずは基本ネタ。

環境:Access2000

参照方法

  1. Dim cn As ADODB.Connection  
  2. Dim Rst As ADODB.Recordset  
  3. Dim i  As Integer  
  4. Set cn = CurrentProject.Connection  
  5. Set Rst = New ADODB.Recordset  
  6. Rst.Open "SELECT * FROM TBS_TEST WHERE SEQNo < 3 ", cn, adOpenForwardOnly, adLockReadOnly  
  7. Do Until Rst.EOF  
  8.     MsgBox (Rst("SEQNo"))  
  9.     Rst.MoveNext  
  10. Loop  
  11. Rst.Close: Set Rst = Nothing  
  12. cn.Close: Set cn = Nothing  

更新

  1. Rst.Open "SELECT * FROM TBS_TEST WHERE SEQNo <= 2", cn, adOpenDynamic, adLockPessimistic  
  2. Do Until Rst.EOF  
  3.     Rst("Data").Value = Rst("SEQNo").Value + 1  
  4.     Rst.Update  
  5.     Rst.MoveNext  
  6. Loop  
  7. Rst.Close  

追加

  1. Rst.Open "SELECT * FROM TBS_TEST WHERE SEQNo <= 2", cn, adOpenDynamic, adLockPessimistic  
  2. Rst.AddNew  
  3. Rst("SEQNo") = 10  
  4. Rst("Data").Value = "新規"  
  5. Rst.Update  
  6. Rst.Close  

CursorTypeやLockTypeはシチュエーションで考えると吉(ヘルプなり確認したまへ)。

構文

  1. Recordset.Open Source,ActiveConnection,CursorType,LockType,Option  

0 件のコメント: