Microsoft KB Archive/265796

= How To Run ADOCE on the Pocket PC Platform =

Article ID: 265796

Article Last Modified on 8/30/2004

-

APPLIES TO


 * Microsoft eMbedded Visual Basic 3.0, when used with:
 * Microsoft Windows CE Platform Software Development Kit for Handheld PC 2000

-



This article was previously published under Q265796



SUMMARY
This article describes how to target the Pocket PC platform with a project built with eMbedded Visual Basic 3.0 (eVB) that uses the Microsoft ADO for Windows CE SDK (ADOCE). A code sample is included to illustrate this functionality.



MORE INFORMATION
To target a Pocket PC device with an eVB application by using ADOCE, the following are required:  eMbedded Visual Basic 3.0.

 The Pocket PC Platform SDK that ships with the eMbedded Visual Tools 3.0.

For information on how to order the eMbedded Visual Tools 3.0, please see the following Microsoft Web site at:

http://www.microsoft.com/mobile/developer/default.asp

 A Pocket PC device (optional).

Step-by-Step Example
Following is a sample that illustrates how to create a table and how to query mSysTables and mSysFields to verify the existence of the table. The database table is created in the \databases folder.  Create a new Windows CE for the Pocket PC project in eMbedded Visual Basic. Form1 is created by default. Add a CommandButton, two Label, and two ListBox controls to Form1. Do not be concerned with the placement of these controls. On the Project menu, click to choose References, and then add a reference to Microsoft CE ADO Control 3.0.</li>  Paste the following code into Form1: Option Explicit

Dim MyRecordSet Dim lMyRecordCount As Long Dim lRecordIndex As Long Dim sMyTable As String

Private Sub Form_Load 'initialize controls Form1.Caption = &quot;CE Database View&quot; Command1.Caption = &quot;Create a Table&quot; Label1.Caption = &quot;Tables:&quot; Label2.Caption = &quot;Fields:&quot; Form1.Move 0, 0, 3705, 4275 Command1.Move 120, 120, 2175, 375 Label1.Move 120, 720, 2000, 255 Label2.Move 120, 2270, 2000, 255 List1.Move 120, 960, 3375, 1230 List2.Move 120, 2520, 3375, 1230 End Sub

Private Sub Command1_Click Dim sSQL Set MyRecordSet = CreateObject(&quot;ADOCE.Recordset.3.0&quot;) On Error Resume Next sSQL = &quot;DROP TABLE TestTable&quot; MyRecordSet.Open sSQL,, 2, 3 MyRecordSet.Close On Error GoTo 0 sSQL = &quot;CREATE TABLE TestTable (Id INT, Title TEXT)&quot; MyRecordSet.Open sSQL,, 2, 3 Set MyRecordSet = Nothing PopulateTableList End Sub

Private Sub PopulateTableList ' Load the ListBox with the Names of Non-System Tables. List1.Clear Set MyRecordSet = CreateObject(&quot;ADOCE.Recordset.3.0&quot;) MyRecordSet.Open &quot;MSysTables&quot;, &quot;&quot;, 1, 3 lMyRecordCount = MyRecordSet.RecordCount For lRecordIndex = 0 To lMyRecordCount - 1 sMyTable = MyRecordSet.Fields(&quot;TableName&quot;).Value If Mid(sMyTable, 1, 4) <> &quot;MSys&quot; Then List1.AddItem sMyTable End If          MyRecordSet.MoveNext Next MyRecordSet.Close End Sub

Private Sub List1_Click Dim sSQL Dim iTableID 'clear the list of fields List2.Clear 'get selected table sMyTable = List1.List(List1.ListIndex) 'obtain the TableID for use in pulling the fields Set MyRecordSet = CreateObject(&quot;ADOCE.Recordset.3.0&quot;) sSQL = &quot;SELECT TableID FROM MSysTables &quot; & _ &quot;WHERE [TableName] = &quot;&quot;&quot; & sMyTable & &quot;&quot;&quot;&quot; MyRecordSet.Open sSQL,, 1, 3 iTableID = MyRecordSet.Fields(&quot;TableID&quot;).Value MyRecordSet.Close 'query mSysFields for the selected table's fields sSQL = &quot;SELECT FieldName FROM MSysFields &quot; & _ &quot;WHERE [TableID] = &quot;&quot;&quot; & iTableID & &quot;&quot;&quot;&quot; MyRecordSet.Open sSQL,, 1, 3 lMyRecordCount = MyRecordSet.RecordCount For lRecordIndex = 0 To lMyRecordCount - 1 List2.AddItem MyRecordSet.Fields(&quot;FieldName&quot;).Value MyRecordSet.MoveNext Next MyRecordSet.Close End Sub

Private Sub Form_OKClick App.End End Sub </li> Run the project. Click the CommandButton to create the table, and then click the table name in the table list to view the fields that you created.</li></ol>

<div class="references_section">