ADO กับ Access 97?
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 356   1
URL.หัวข้อ / URL
ADO กับ Access 97?

มีคนถามคำถามที่กลับกันไว้ที่ 
 
http://www.utteraccess.com/forums/showflat.php?Cat=&Board=access_2000&Number=116246&page=0&view=collapsed&sb=5&o=7&fpart=1 
 
ADO to DAO conversion question... 
What I've got is a database that has been developed on Access 2000,  
however, it is to be deployed on a machine as a stand database but in  
Access97 format. I was going to use the convert to a prior version feature until I  
remembered good old DAO.  
 
My question is, can I convert an ADO heavily coded Access2000 database as  
an Access97 database or do I have to delve into DAO for coded recordsets  
and so on? 
 
Any advice welcome... 
 
Cheers, 
 
ih.  
 
เขาถามว่าต้องการจะแปลงไฟล์ A2K มาใช้เป็น A97 แต่มีโค้ดเป็น ADO จำนวนมาก จะได้หรือไม่ 
 
ผมเลยร่วมแจมด้วย ว่า น่าจะไม่มีปัญหานะ เพราะผมเองก็ใช้ ADO กับ A97 เหมือนกัน แต่เป็นการ Connect ไปอ่านข้อมูลจาก SQL Server และ Oracle ซึ่งสามารถจะแก้ไข หรือเพิ่มข้อมูลได้ 
น่าจะทำได้นะ 
ผมเลยถามเขาต่อไปว่า แล้วมีอะไรที่ A97 จะไม่สามารถเล่น ADO ได้หล่ะ 
 
เขาเลยตอบมาว่า ใช้ Recordset แล้ว Count ให้ค่าไม่ถูกต้อง 
 
ผมเลยนึกได้ว่าการใช้ RecordsetCount ธรรมดาจะมีปัญหากับ ADO ซึ่งเป็นที่รู้จักกันดีอยู่แล้ว 
ผมเลยได้ลองทำตัวอย่าง เพื่อให้เขาได้เห็นถึงแนวทางแก้ไขปัญหาดังกล่าว จึงได้พบว่า CurrentProject ไม่มีใน A97 แต่ผมก็เลี่ยงโค้ดไปใช้ตามตัวอย่างข้างล่าง 
 
จากตัวอย่าง เป็นการเปิด Recordset ใน 3 รูปแบบ เพื่อแสดงให้เห็นผลของการใช้ Count ให้ได้ค่าที่ถูกต้อง ลองดูโค้ดครับ 
 
Sub CountRecordset() 
   Dim cnn As New ADODB.Connection 
   Dim rst As New ADODB.Recordset 
    
   cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _ 
        "Data Source=" & CurrentDb.Name & " ;" 
   'Set cnn = CurrentProject.Connection 
    
   Set rst = cnn.Execute("Select * from Farmers") 
    
   Do While Not rst.EOF 
         Debug.Print rst(0) & "  " & rst(1) 
         rst.MoveNext 
    Loop 
    Debug.Print "Method 1---> " & rst.RecordCount 
    rst.Close 
     
    Set rst = cnn.Execute("Select Count(*) from Farmers") 
    Debug.Print "Method 2---> " & rst(0) 
    rst.Close 
     
    With rst 
      .Source = "Select * from Farmers" 
      .CursorType = adOpenForwardOnly 
      .LockType = adLockReadOnly 
      .ActiveConnection = cnn 
      .CursorLocation = adUseClient 
      .Open 
   End With 
   Debug.Print "Method 3 ---> " & rst.RecordCount 
    
rst.Close 
cnn.Close 
Set rst = Nothing 
Set cnn = Nothing 
 
End Sub *** Edited by Supap Chaiya *** 7/5/2546 21:28:13

1 Reply in this Topic. Dispaly 1 pages and you are on page number 1

1 @R06566
   
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0429s