Creating Mobile Solutions for Visual FoxPro Developers, part 2
Intro
In the 1st part of this mini serie I focused on the ASP.NET controls and the UI-aspect of them. I will continue in this 2nd and last part to connect data to these UI-controls and will try to show you how you can build a nice web-based presentation layer for your VFP-apps that are able to target multiple mobile devices.
Working with Data
Data access is a vital part of any application. There are very few Visual FoxPro applications that don't require the use of data. Mobile applications must also access dynamic data. The .NET Framework includes a set of data access namespaces and classes called ADO.NET. ASP.NET uses ADO.NET to implement its data handling. ADO.NET is specifically designed to optimize data access using either OLE DB or XML. The object model (see the figure below) is similar to that of ADO and consists of a Connection object (that provides connectivity to a data source) and a Command object (that executes commands on the database to return or modify data, run stored procedures, and so on). In addition, you can use ADO.NET as a robust, hierarchical, disconnected data cache to work with data offline. Use the central disconnected object, the dataset, to sort, search, filter, store pending changes, and navigate through hierarchical data.
When designing mobile applications, you can access data using two different approaches: using the Visual FoxPro OLE DB provider to access the tables directly or to direct the mobile application to call a Visual FoxPro COM object that retrieves the data and returns XML.

The ADO.NET object model
Using the Visual FoxPro OLE DB Provider for Direct Data Access
Developers can use the Visual FoxPro OLE DB provider to access the tables directly and bind them to controls, so that they can be displayed and modified in a mobile form. The OLE DB provider implements a set of COM interfaces that allows access to the data in a standard row/column format. The OLE DB provider supports the Visual FoxPro database events. You can call stored procedures (even those that require parameters), and access triggers, rules, and default values in the database container. In Visual FoxPro 8.0, the OLE DB provider is enhanced to provide even greater compatibility with ADO.NET. The following code example shows how to retrieve records from a customer's Visual FoxPro table and display the results in a List control.
Dim connStr As String = "Provider=VFPOLEDB.1;Data Source=" & _
"C:\SAMPLES\DATA\TESTDATA.DBC"
Dim strSQL As String = "SELECT * FROM Customer"
Dim oda As New OleDbDataAdapter(strSQL, connStr)
Dim ds As New DataSet()
oda.Fill(ds, "CustomerInfo")
'Assign DataSet to List control
lstCountry.DataTextField = "Country"
lstCountry.DataValueField = "Country"
lstCountry.DataSource = ds
lstCountry.DataBind()
The same functionality can be used to access SQL Server data (version 7.0 and later) using the ADO.NET SQL Client Data Provider. The provider implements the same base classes as the OLE DB provider. The following code is the preceding example using SQL Server data.
Dim connStr As String = "Data Source=(local);" & _
"Initial Catalog=Northwind;" & _
"Integrated Security=SSPI;" & _
"Persist Security Info=False"
Dim strSQL As String = "SELECT * FROM Customers"
Dim oda As New SqlDataAdapter(strSQL, connStr)
Dim ds As New DataSet()
oda.Fill(ds, "CustomerInfo")
'Assign DataSet to List control
lstCountry.DataTextField = "Country"
lstCountry.DataValueField = "Country"
lstCountry.DataSource = ds
lstCountry.DataBind()
Using Visual FoxPro COM Objects for Data Access
Visual FoxPro is a great tool for building middle-tier components based on its data access and string manipulation. It provides developers with the capability to create component-based software applications. Visual FoxPro 8.0 introduces new features for even greater control when working with data inside your COM objects.
Visual FoxPro 8.0 provides enhancements to XML support—in particular, increased compatibility with Visual Studio .NET datasets and diffgrams. The XMLAdapter class supports hierarchical XML format that improves the capability of Visual FoxPro to interoperate with XML produced from and written to .NET datasets. Visual FoxPro 8.0 can read from and write to hierarchical XML and convert it to separate native cursors. When the XML is hierarchical, but does not represent a collection of related tables, it uses one table that represents the result of a multitable SQL Join command. Only one Visual FoxPro cursor is created.
* VFP Sample XMLAdpater Code
&& Create XMLAdapter
oXMLAdapter = NEWOBJECT("XMLAdapter")
&& Set XML type to be Diffgram
oXMLAdapter.IsDiffgram = .T.
&& Add cursor with schema information
oXMLAdapter.AddTableSchema(customers)
oXMLAdapter.AddTableSchema(orders)
&& Export tables to hierarchial XML
oXMLAdapter.ToXML("cXML")
Return cXML
The following is a code example written in Visual Basic .NET that shows how to call the Visual FoxPro COM object.
' VB .NET Sample Code Calling VFP COM Object
' Call VFP COM object
Dim oCustomer As New Customer()
' Call method of COM object to fetch data
Dim cXML As String
cXML = oCustomer.GetData()
' Read XML into a DataSet
Dim ds As New DataSet()
ds.ReadXml(New StringReader(cXML))
Extending Your Visual FoxPro Applications
When Visual FoxPro developers use the ASP.NET Mobile Controls, they can leverage existing applications to reach new users. Information can be extracted from the application and rendered on mobile devices to enable users who cannot access the information they are seeking. Think of sales managers on the road that need sales figures for each of their stores. In this situation, they can use an Internet-enabled mobile phone or Pocket PC to access an ASP.NET mobile Web site that delivers sales information to their mobile devices. The managers control when they access the sales figures. They do not rely on someone from the home office to provide the information through a fax or telephone. The Visual FoxPro information can be retrieved through direct data access using the OLE DB provider or business objects using COM. By using ASP.NET Mobile Controls, you can give the power to users to decide when and where they want information, without having to run the Visual FoxPro application.
Conclusion
As the availability of mobile-device technology and high-speed wireless networks increases, consumer demand for mobile-based content and features to expand Visual FoxPro applications also increases. As a result, you can leverage the power of ASP.NET Mobile Controls to provide information to consumers through reliable, mobile Web applications. ASP.NET Mobile Controls offer developers an infrastructure to build robust applications that integrate with the look and feel of existing systems. They have a great potential to influence the way people deal with information and the environments within which it can be accessed and used.