DEVBUZZ Homepage Pocket Access Data provider for the .NET Compact Framework
 
Web www.devbuzz.com
  HOME PAGE
  All Articles
  Advertise
  Consulting

 Development
  Discuss - Forums
  Still in the box?
  .Compact Framework
  Code Snippets
  SQL Server CE
  Database
  MS Resources
 Stores
  Developer Controls
  Pocket PC Hardware
  Pocket PC Software
  Pocket PC Books
  .NET CF Books
  Book Reviews
  SPB SW Discounts
  RESCO SW Discounts
 DEVBUZZ Info
  About Us
  Help
  Join our email list
  Links & Ratings
  Press & Comments
  Pocket PC version
  Software Reviews
  Hardware Reviews
 Authors
  Authors
  Article Guide
  Competitions
 Resources
  Developers
  Register
  Login

  SPB Discounts!
 Columnists
  Rick Winscot
 Past Blast
  Personal Media Ctr
  Gizmobility
  eVB Legacy
  Old news
  Hosted Software
  Wireless
  Newsletters
  Carl Davis
  Upton Au

 Pocket PC Registry
  Join the registry
  View current list
 Current Poll
Are you converting to .NET Compact Framework?
Yes, it has changed my life!
No, I'm sticking with eVB
.NET CF what's that`?

Current results
3431 votes so far
 Recent Forum Threads [goto forums]

Get Computername
read... (67 hits)


Great aid to development productivity
read... (82 hits)


ThreadingTimer sample code
read... (143 hits)


Multithreading with .NET CF
read... (194 hits)


Moving from eMbedded Visual Basic to Visual Basic .NET
read... (166 hits)


.NET Compact Framework 2.0 Service Pack 2
read... (226 hits)


Transfer Data from SQL Server 2000 to SQL Server Compact Edition
read... (298 hits)


This protocol version is not supported
read... (236 hits)


Converting Lowercase to uppercase wont work
read... (203 hits)


Direct access to MS SQL Server 2000
read... (374 hits)


Creating SDF file in Desktop
read... (513 hits)


Winsock in CF.NET
read... (316 hits)


Using Pocket Outlook to submit HTML page form with MAILTO action
read... (420 hits)


Missing file "System.Data.PocketPC.asmmeta.dll"
read... (268 hits)


HP iPAQ hw6915 Serial Port Issue
read... (309 hits)


Info on the recent forum changes
read... (341 hits)


SqlServer tools from Redgate
read... (383 hits)


Arrow keys and Hardware navigation button
read... (393 hits)


O2 XDA lls pin sync cable to comport
read... (322 hits)


Creating dynamic folders on Pocket PC OS
read... (299 hits)

Custom Windows Mobile software development.
LBS Challenge 2007
LBS Challenge Eight previous NAVTEQ Global LBS Challenge® participants have received venture capital funding and nine past LBS Challenge winners have launched commercial applications on major wireless carriers. Register your non-commercial LBS application in the 2007 NAVTEQ Global LBS Challenge in one of three regions: Americas, Europe-Middle East-Africa (EMEA) or Asia-Pacific(APAC). You could win a share of $2 million in prizes. This could be your year.
Dream. Develop. Win.

Development | .NET Compact Framework

Pocket Access Data provider for the .NET Compact Framework
Written by Peter Foot  [author's bio]  [read 103591 times]
Edited by Derek

Download the code   Discuss this article   .NET Compact Framework   

Page 1  Page 2  Page 3 

Why Pocket Access?

The omission of a Pocket Access database provider has sparked much discussion from the very first release of the .NET Compact Framework. While Microsoft had provided developers with SQL Server CE, there is still a strong need for Pocket Access databases, both for updating applications previously written in eVB, and for any other application where installation of SQL Server CE could be considered overkill. With this in mind I wrote a wrapper library around the familiar ADOCE ActiveX control.

What is ADOCE .NET Wrapper?

The ADOCE .NET Wrapper is a combination of .NET classes and an unmanaged C++ dll which provides the bridge with the ActiveX control. To Use ADOCE from your .NET applications you add the ADOCE .NET Wrapper as a reference to your project.

Add Reference dialog

The objects, methods and properties available to you should be very familiar if you have used the ADOCE control with eVB. The objects are all contained within the InTheHand.AdoceNet namespace, so when you are using this from your VB.NET code you should add an imports directive to your code file so that you dont have to type out the fully qualified names each time:

Imports InTheHand.AdoceNet

Connecting to a Database

You open a connection to a Pocket Access file using the Connection object. The following code snippet shows how to open the file Trees.cdb from the My Documents folder of the device:

Dim cnDataFile As Connection
cnDataFile = New Connection()

'pass full filename to open method
cnDataFile.Open(\My Documents\Trees.cdb)

With a single Connection you can then go on to query the database with several Recordset objects.

Retrieving Records

The Recordset is the core object within the ADOCE .NET Wrapper. With it you can issue SQL queries and return views of your data. The following code snippet shows a query to select Tree names from the database with a height greater than 3 metres.

'create and initialise a new Recordset
Dim rsTrees As Recordset
rsTrees = New Recordset()

'store SQL statement
Dim SQL As String
SQL = _
   "SELECT TreeName FROM Trees WHERE Height > 3"

rsTrees.Open(SQL, cnDataFile, _
   LockType.Optimistic, CommandType.Text)

Note that the LockType and CommandType are optional, by specifying just a query and a Connection the Recordset is opened Read-Only. The values within the table are held within the Recordset object, and we can extract them from a specific location, loop through the table or use a new feature of .NET Compact Framework Data Binding.

Populating Lists

A traditional way of filling a list from a Recordset is to use a While Not loop that exits when the Recordset.EOF flag is True. The BOF and EOF properties indicate positions before and after valid rows in the Recordset. Here is a code snippet to demonstrate filling a ListView from a Recordset:

'loop while there are still records
While Not rsTrees.EOF

   'create new listview item
   Dim lviNewItem As ListViewItem 

   'assign index field value to item text
   Dim strIndex As String
   strIndex = rsTrees.Fields("Index").ToString
   lviNewItem = New ListViewItem(strIndex)

   'add tree name as sub-item
   Dim strTreeName As String
   strTreeName = _
      rsTrees.Fields("TreeName").ToString
   lviNewItem.SubItems.Add(strTreeName)

   'add the item to the list
   lstTreeList.Items.Add(lviNewItem)

   'move to the next record
   rsTrees.MoveNext()

End While

Next Page 

Back to .NET Compact Framework | [Article Index]

 

Back to the top of the page.
Chris De Herrera's Windows CE Website Windows CE News & Information Source
Copyright ©2000-2007 by DEVBUZZ.COM, Inc., NJ. USA.MSDEVELOP