Q196034: HOWTO: Use ADOFILTR.DLL to Transfer Database Tables
Article: Q196034
Product(s): Microsoft Visual Basic for Windows
Version(s): 5.0,6.0
Operating System(s):
Keyword(s): kbAPI kbDatabase kbToolkit kbVBp kbVBp500 kbVBp600 kbOSWinCEsearch kbGrpDSVB kbDSupport
Last Modified: 23-AUG-2001
-------------------------------------------------------------------------------
The information in this article applies to:
- Microsoft Visual Basic Learning Edition for Windows, versions 5.0, 6.0
- Microsoft Visual Basic Professional Edition for Windows, versions 5.0, 6.0
- Microsoft Visual Basic Enterprise Edition for Windows, versions 5.0, 6.0
-------------------------------------------------------------------------------
SUMMARY
=======
This article demonstrates how to use the ADOCE API (the ADOFILTR.DLL exports) in
Visual Basic to programmatically import and export data tables between the
desktop and a remote device.
MORE INFORMATION
================
ADOFILTR.DLL, Pocket Access file converter and synchronizer, is a part of the
ActiveX Data Objects 2.0 SDK for Windows CE (ADOCE 2.0). It allows programmatic
transfer of database tables between the host desktop computer and the remote
device. It runs on the desktop computer, not the remote device. The desktop
initiates and controls the transfer process. For additional information on ADOCE
2.0, please see the following article in the Microsoft Knowledge Base:
Q238947 FILE: Msadoce2.exe Installs ADO for Windows CE SDK
The sample code provided below transfers a table in the Biblio.mdb sample
database between the desktop and the remote device. Before trying this sample,
you need to make sure that ADOCE 2.0 is already installed on the remote device.
Modify Biblio.MDB
-----------------
Referential integrity rules may interfere with table import. Therefore, the
Biblio database must be modified to have a table without relationships. You can
use the Visual Data Manager add-in in Visual Basic to modify Biblio.MDB and
create a new table.
1. In the Visual Data Manager, open Biblio.MDB.
2. In the SQL window, insert and execute the following SQL statement:
SELECT Authors.* INTO Authors2 FROM Authors WHERE (Authors.AU_id < 50)
This will create a new table called "Authors2" with the data from the original
Authors table.
Create the Project to Import and Export Tables
----------------------------------------------
1. In Visual Basic, create a new standard EXE project. Form1 is generated by
default.
2. Add a CommandButton (Command1) to Form1. Set the caption property to "Device
to PC."
3. Add a second CommandButton (Command2) to Form1. Set the caption property to
"PC to Device."
4. Add the following code to the declarations section of the form module:
Private Declare Function DESKTOPTODEVICE _
Lib "c:\program files\windows ce services\adofiltr.dll" _
(ByVal desktoplocn As String, _
ByVal tablelist As String, _
ByVal sync As Boolean, _
ByVal overwrite As Integer, _
ByVal devicelocn As String) As Long
Private Declare Function DEVICETODESKTOP _
Lib "c:\program files\windows ce services\adofiltr.dll" _
(ByVal desktoplocn As String, _
ByVal tablelist As String, _
ByVal sync As Boolean, _
ByVal overwrite As Integer, _
ByVal devicelocn As String) As Long
5. Add the following code to the Click event procedure of Command1:
Dim result As Long, sPath As String, sTableList As String
spath = "c:\Program Files\DevStudio\VB\biblio.mdb"
sTableList = "Authors2.."
' Change mouse pointer to hourglass.
Screen.MousePointer = vbHourglass
' import table from remote device.
result = DEVICETODESKTOP( sPath, sTableList, False, False, "")
' Return mouse pointer to normal.
Screen.MousePointer = vbDefault
If result = 0 Then
MsgBox "Transfer Successful"
Else
MsgBox "An error occurred transferring the data: " & result
End If
6. Add the following code to the Click event procedure of Command2:
Dim result As Long, sPath As String, sTableList As String
spath = "c:\Program Files\DevStudio\VB\biblio.mdb"
sTableList = "Authors2.."
' Change mouse pointer to hourglass.
Screen.MousePointer = vbHourglass
'Export table to remote device.
result = DESKTOPTODEVICE(sPath, sTableList, False, False, "")
' Return mouse pointer to normal.
Screen.MousePointer = vbDefault
If result = 0 Then
MsgBox "Transfer Successful"
Else
MsgBox "An error occurred transferring the data: " & result
End If
NOTE: The paths given in the declaration and procedures are for default
Installations; modify them according to your system.
Errors that may occur (not an exhaustive list):
-2147024894 The remote device may not be connected properly, or ADOCE 1.0 was
not installed or registered correctly on the remote device. To install ADOCE
1.0 on the remote device, you need to click on Start, Programs, Microsoft
ADOCE 1.0 and then Install ADOCE on HPC while the device is connected to the
desktop machine and communication is OK.
-2146824447 The destination table may already exist on the desktop and
Overwrite was set to False, or Overwrite was set to True but the table is not
allowed to be overwritten. A log file may also display.
-2147217865 This error may occur if an attempt is made to import a table does
not exist from the remote device.
NOTE: The values above are the result of subtracting the vbObjectError constant
from the raw error value.
REFERENCES
==========
Microsoft Windows CE ActiveX Data Objects SDK 2.0 Help
Additional query words: wce adoce dao ado wince vbce vbce5 vbce6
======================================================================
Keywords : kbAPI kbDatabase kbToolkit kbVBp kbVBp500 kbVBp600 kbOSWinCEsearch kbGrpDSVB kbDSupport kbATM
Technology : kbVBSearch kbAudDeveloper kbZNotKeyword6 kbZNotKeyword2 kbVB500Search kbVB600Search kbVB500 kbVB600
Version : :5.0,6.0
Issue type : kbhowto
=============================================================================
THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.
Copyright Microsoft Corporation 1986-2002.