Microsoft KB Archive/207562

= How To Delete Tables from a Windows CE Device from VBCE or eVB =

Article ID: 207562

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Windows CE Toolkit for Visual Basic 6.0
 * Microsoft eMbedded Visual Basic 3.0

-



This article was previously published under Q207562



SUMMARY
There is currently no functionality provided on a Windows CE device by which database tables existing in the database store can be directly deleted. This article illustrates how this can be accomplished from a Windows CE Toolkit for Visual Basic (VBCE) or eMbedded Visual Basic application.



MORE INFORMATION
The following steps illustrate how to delete non system tables from the database store. The assumption is made that there are already tables in existence on the Windows CE device that can be deleted.

Step by Step Example
 Create a new Windows CE project in either Visual Basic or eMbedded Visual Basic. Form1 is created by default. Place a list box and a command button on Form1. From the Project menu, choose References and add a reference to either the Microsoft CE ADO Control 3.0 or Microsoft CE ADO Control 3.1, whichever is the most current version on your computer.  Paste the following code into the code window of Form1: Option Explicit

Private Sub Form_Load Dim MyRecordSet Dim lMyRecordCount As Long Dim lRecordIndex As Long Dim sMyTable As String 'initialize controls Command1.Caption = "Drop Selected Tables" Form1.Caption = "CE Drop Tables" Command1.Move 60, 1920, 4695, 495 List1.Move 60, 60, 4695, 1815 Form1.Move 0, 0, 4950, 2880 ' Load the ListBox with the Names of Non-System Tables. Form1.List1.Clear Set MyRecordSet = CreateObject("ADOCE.Recordset") MyRecordSet.Open "MSysTables", "", 1, 3 lMyRecordCount = MyRecordSet.RecordCount For lRecordIndex = 0 To lMyRecordCount - 1 sMyTable = MyRecordSet.Fields("TableName").Value If Mid(sMyTable, 1, 4) <> "MSys" Then Form1.List1.AddItem sMyTable End If       MyRecordSet.MoveNext Next MyRecordSet.Close End Sub

Sub Command1_Click Dim iIndex As Integer Dim MyRecordSet

Set MyRecordSet = CreateObject("ADOCE.Recordset") For iIndex = Form1.List1.ListCount - 1 To 0 Step -1 If Form1.List1.Selected(iIndex) Then MyRecordSet.Open "DROP TABLE [" & _ Form1.List1.List(iIndex) & "]",, 2, 3 Form1.List1.RemoveItem (iIndex) End If   Next End Sub Note that the CreateObject statements may need to be changed depending on whether you have ADOCE 3.0 or 3.1 on your computer.  Run the project.

Note that you can select and delete the non system tables from the database store of your Windows CE device.

