Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem converting empty date to DataSet
Message
 
À
20/08/2013 14:18:23
Joel Leach
Memorial Business Systems, Inc.
Tennessie, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Visual FoxPro et .NET
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01580842
Message ID:
01581030
Vues:
68
Most other languages don't have the concept of a 'empty' data. xBase dialects are fairly unique with that. In order dbs you tend to use NULL values to represent empty dates.

When I needed to deal with this I tend to fix up the dates with some static date like {^1900-01-01 } and then do the CursorToXml conversion.

FWIW, another option for passing FoxPro data sets to .NET is by using Collections:
************************************************************************
*  CursorToCollection
****************************************
FUNCTION CursorToCollection(lcCursor)
LOCAL loItem, loCol as Collection

loCol = CREATEOBJECT("Collection")
IF EMPTY(lcCursor)
  lcCursor = ALIAS()
ENDIF
  
SELECT (lcCursor)
SCAN
   	SCATTER NAME loItem MEMO
   	loCol.Add(loItem)
ENDSCAN

RETURN loCol
ENDFUNC
*   CursorToCollection
and pass the resulting object to .NET. You still will have to deal with the empty dates though although I believe in this case FoxPro empty dates will default to a low value .NET date (DateTime.MinDate?).

If you are using XML I'd also recommend you use XMLAdapter instead of CursorToXml. There are a number of improvements in the schema it generates and the code is considerably faster than cursor to Xml.
************************************************************************
* CursorToXmlString
****************************************
***  Function: A generic routine that returns an XmlAdapter XML result
***            of a single table that can be loaded into a .NET 
***            DataSet. The table is encoded with the name of the
***            alias.
***      Pass: lcAlias  - Optional: Name of the cursor alias to encode
***    Return: Xml string
************************************************************************
FUNCTION CursorToXmlString(lcAlias)
LOCAL lcXML

IF EMPTY(lcAlias)
  lcAlias = ALIAS()
ENDIF

lcXML = ""
LOCAL oXA as XMLAdapter
oXA = CREATEOBJECT("XMLAdapter")
*** lcTable doesn't exist - error here (use ALIAS() )
oXA.AddTableSchema(lcAlias,.T.,STRCONV(lcAlias,5))
oXA.ToXML("lcXML")
RETURN lcXML
ENDFUNC
* CursorToXmlString
Hope this helps,

+++ Rick ---

>I am returning a cursor from FoxPro using CursorToXML(lcAlias,"lcXML",1,0,0,"1"), then converting the XML to a DataSet in .NET. It works well unless the cursor includes empty dates. .NET doesn't like them. It wants NULLs, meaning the field element is excluded altogether in the XML. I can work around the issue by not including a schema, but that treats everything as a string and doesn't meet my needs. I don't want to replace the empty date fields with NULL in FoxPro. I could strip the empty fields out of the XML on the .NET side before loading the XML into a DataSet, which is ok, but I'm wondering if there is a better solution? I have read Message #1199897, but that didn't work for me.
>
>Thanks.
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform