03-30-2022 12:09 PM
I'm using the .NET SqlDataReader class, MS says there's a This[]/Item[] property:
Connection |
Gets the SqlConnection associated with the SqlDataReader. |
Depth |
Gets a value that indicates the depth of nesting for the current row. |
Field |
Gets the number of columns in the current row. |
Has |
Gets a value that indicates whether the SqlDataReader contains one or more rows. |
Is |
Retrieves a Boolean value that indicates whether the specified SqlDataReader instance has been closed. |
Item[Int32] |
Gets the value of the specified column in its native format given the column ordinal. |
Item[String] |
Gets the value of the specified column in its native format given the column name. |
Records |
Gets the number of rows changed, inserted, or deleted by execution of the Transact-SQL statement. |
Visible |
Gets the number of fields in the SqlDataReader that are not hidden. |
LabView doesn't:
I wrote a C# class method as a workaround because it was convenient and I have VS,
public static object DbGetField(SqlDataReader r, int i) {return r[i];}
but how do go direct in LV to do this?
Solved! Go to Solution.
03-30-2022 12:56 PM - edited 03-30-2022 01:25 PM
I believe I see what's going on, it seems the properties available through LabVIEW are limited to numeric and string properties - that This[]/Item[] are .NET objects instead. Maybe there's a recipe for casting to more generic/specific .NET objects. EDIT: Looking at it again, I see I have no issues in adding .NET objects to a .NET class and it shows up in LabVIEW - so my assertion that because it's not a numerical or string object doesn't hold water.
03-30-2022 03:19 PM - edited 03-30-2022 03:20 PM
You are correct in that it is perfectly fine for properties to return objects.
The root cause here is that the LabVIEW only supports property syntax for "pure" properties - ie IL methods that take no parameters and return the specified data type. Recall that, for pure IL (which .NET assemblies are built on), properties are just metadata specifying pre-defined methods (eg. "get_name") backing that property. Here is the content for the Item "properties"
.property instance object Item(
int32 i
)
{
.get instance object System.Data.SqlClient.SqlDataReader::get_Item(int32)
}
.property instance object Item(
string name
)
{
.get instance object System.Data.SqlClient.SqlDataReader::get_Item(string)
}
As you can see, the metadata for both properties specifies a backing IL method for each "get_Item". Since LabVIEW doesn't support properties backed by methods that take parameters, you can call the "get_Item()" method of choice using an Invoke node in LabVIEW instead.
03-31-2022 04:13 AM
You'd probably need to use an iterator. This is probably handled by C#\.NET automatically. Doing this in LabVIEW is sloooooow.
IIRC, I've make a small assembly that returns a 2D array .NET object of objects. Converting a 2D array .NET object in LabVIEW is pretty fast. Don't return a 2D array of .NET objects, that's slow.
If you post a small example of what you have, I could have a closer look.