VFP 7.0 and ADO.NET DataSets

by Brian Jepson

As I worked on the slides for an upcoming talk on .NET webservices, I developed a few examples to go along with the talk. It was easy to put together web service consumers in C#, but Visual FoxPro wasn't so easy (for me), since I hadn't done professional FoxPro development in many years. But I had to get a FoxPro example out, since the talk is being sponsored by a Visual FoxPro user group. As usual, I checked Google, but I wasn't encouraged by what I found.

So, I pulled the XML-serialized data set into a text file and started mercilessly chopping away at it until I had something I could feed into Visual FoxPro's XMLTOCURSOR() function.

When I get the data set back from the .NET web service, it looks roughly like this:

<DataSet> ...
<xs:schema> ... </xs:schema>
<diffgr:diffgram> ...
<NewDataSet> ... </NewDataSet>

I figured out that what I wanted was the <NewDataSet> element and everything it contained. The only problem is that some of the elements in it contain references to outer namespaces, as in:

<Authors diffgr:id="Authors2" msdata:rowOrder="1">

By stripping these out, I ended up with something I could feed into XMLTOCURSOR() and browse (see Figure 1). Here is the listing for my Visual FoxPro program:

* IntelliSense-generated code appears here *

LOCAL dotnetDS as String
LOCAL vfpDS as String
LOCAL dsrows as String

* Get the .NET Data set. It looks like:
* <DataSet> ...
* <xs:schema> ... </xs:schema>
* <diffgr:diffgram> ...
* <NewDataSet> ... </NewDataSet>
* </diffgr:diffgram>
* </DataSet>
* We want the NewDataSet, since it contains the rows.
dotnetDS = oWS.GetAuthors
dsRows = dotnetDS.item[1].firstChild.xml

* strip out references to XML namespaces that are
* no longer part of this XML document.
vfpDS = STRTRAN(STRTRAN(dsRows, "diffgr:", ""), "msdata:", "")

* Perform the conversion.

* See how it looks!

Not quite XSLT, but it got the job done quickly and easily!

For documentation on registering web services with Visual FoxPro and using IntelliSense to insert consumer code, see this MSDN article.

Figure 1. Browsing the a .NET data set.

My FoxPro skills are rusty, but this approach works for me. I'd be interested to hear how others have approached this issue. Did I make this more complicated than it needed to be?


2002-01-29 15:16:03
Looks like you came up with a nice, clean solution here.
It'll be interesting to see if anyone has any better suggestions.
2002-01-30 09:29:05
So, how'd the meeting last night go?(n/t)
2002-02-01 07:55:40
So, how'd the meeting last night go?(n/t)
It went well, thanks. They were a great audience, and had some excellent questions. In particular, they had a lot of questions about the .NET CLR, which is a talk in and of itself. I think the next time I use this presentation, I should add some slides that anticipate some of the CLR questions.
2003-11-20 16:14:46
Fox Pro 8.0
Any one know of a starter book or set of books for a Fox Pro wanna be?

Send replies to tlbeavers3@cox.net