Skip to main content

Past Blast

Featured Products

Windows Mobile Developer Controls
Windows Mobile Developer Controls
Stay in touch using the DEVBUSS RSS feeds.
 

News

Windows Mobile Developer Controls
Sapphire Soltuions

Forcing Database Changes from ADOCE to Commit

Written by Christopher Tacke  [author's bio]  [read 40491 times]
Edited by Derek

Page 1  Page 2 

ADOCE is a fantastic tool allowing eVB programmers easy access to the native data store, Pocket Access and SQL Server 2000 CE Edition databases. It has a subset of the desktop ADO objects, properties and methods and makes using databases a snap. Unfortunately, it has some flaws. One of the most disturbing problems is that if you're using ADOCE to modify data in a database, including inserts, deletes and updates, the modifications are not fully committed to the database volume until your application exits. This holds true for ADOCE 3.0 and 3.1 on the Pocket PC and HPC.

To see what I mean, create a simple project and use the Recordset object to insert data into a table. Create a project with a single form and add 3 Command Buttons and a ListBox to it. Something like Figure 1.

Then add the following code to the form's code page:

Private rs As ADOCE.Recordset
Private cn As ADOCE.Connection

Private Sub Command1_Click()
On Error Resume Next
' Open the connection
cn.ConnectionString = ""
cn.Open
' Create the DB
' not graceful, but if the DB exists,
' the On Error will handle this
cn.Execute "CREATE DATABASE '\ADOCETest.cdb'"
' change the connection to our DB
cn.Close
cn.ConnectionString = "\ADOCETest.cdb"
cn.Open
' create the table
cn.Execute "CREATE TABLE " _
& "TestTable(Name varchar(30))"
cn.Close
End Sub

Private Sub Command2_Click()
cn.ConnectionString = "\ADOCETest.cdb"
cn.Open
' Insert data
cn.Execute "INSERT INTO TestTable " _
& "VALUES('Fred')"
cn.Execute "INSERT INTO TestTable " _
& "VALUES('Wilma')"
cn.Execute "INSERT INTO TestTable " _
& "VALUES('Barney')"
cn.Execute "INSERT INTO TestTable " _
& "VALUES('Betty')"
cn.Close
End Sub

Private Sub Command3_Click()
cn.ConnectionString = "\ADOCETest.cdb"
cn.Open
' retrieve the data
Set rs = cn.Execute("SELECT * FROM TestTable")
' clear the list
List1.Clear
' display the data
Do While Not rs.EOF
List1.AddItem rs.Fields("Name").Value
rs.MoveNext
Loop
cn.Close
End Sub

Private Sub Form_Load()
Set cn = CreateObject("ADOCE.Connection.3.0")
End Sub

Private Sub Form_OKClick()
App.End
End Sub

Now let's expose the "soft underbelly" of ADOCE. Run the application and tap the first button to create the database and table, then exit the application. It is important that you exit the application at this point to ensure the table is created.

Next, re-start the application and tap the second two buttons in succession to populate our table and then retrieve and show the data. You should get an output like Figure 2. We've inserted 4 records into our table, or have we?

Next Page