FoxPro and .NET Interop
Access .net Dataset from DotnetBridge
Gravatar is a globally recognized avatar based on your email address. Access .net Dataset from DotnetBridge
  radicand
  All
  May 21, 2020 @ 09:42am

How can you access the DataRow.Item[] collection of a DataSet? -Without using the .Datasettocursors - I'm trying not to use FoxPro's xml adapter

Gravatar is a globally recognized avatar based on your email address. re: Access .net Dataset from DotnetBridge
  Rick Strahl
  radicand
  May 21, 2020 @ 02:07pm

It's not easy and very inefficient. I don't think there's a way to access the named, indexed row or table collections at all - only by index ordinal.

CLEAR
do wwDotNetBridge
LOCAL loBridge as wwDotNetBridge
loBridge = GetwwDotnetBridge()

*** Load our custom assembly
? loBridge.LoadAssembly("InteropExamples.dll")
? loBridge.cErrorMsg


loFox = loBridge.CreateInstance("Westwind.WebConnection.TypePassingTests")
?  loFox

*** Returns
loDS = loFox.GetDataSet()
? loDs

*** Note the DataSet related Properties rquire GetPropertyEx/SetPropertyEx/InvokeMethodEx
loTable = loBridge.GetPropertyEx(loDs,"Tables[0]")
? loBridge.ToString(loTable)

loRows = loBridge.GetPropertyEx(loTable, "Rows")
? loBridge.ToString(loRows)

lnRecs = loBridge.GetPropertyEx(loRows,"Count")
? lnRecs

FOR lnX = 0 TO lnRecs - 1
	loRow = loBridge.GetPropertyEx(loTable,"Rows[" + TRANS(lnX) +  "]")

    ? loBridge.GetPropertyEx(loRow,"ItemArray[0]")
    ? loBridge.GetPropertyEx(loRow,"ItemArray[1]")
    ? loBridge.GetPropertyEx(loRow,"ItemArray[2]")
    ? 
ENDFOR

If you iterate over the list it'll be very slow because everything goes through COM and multiple slow reflection calls. This is why serialization is recommended. In most cases the serialization deserialization actually is faster than this nasty and hard to read code.

This would only make sense if you need to get at a few values out of a much larger dataset. Anything else serializing deserializing will be more efficient.

+++ Rick ---

© 1996-2020