LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to get This[], DOTNET current instance

Solved!
Go to solution

I'm using the .NET SqlDataReader class, MS says there's a This[]/Item[] property:

Properties

Connection

Gets the SqlConnection associated with the SqlDataReader.

Depth

Gets a value that indicates the depth of nesting for the current row.

FieldCount

Gets the number of columns in the current row.

HasRows

Gets a value that indicates whether the SqlDataReader contains one or more rows.

IsClosed

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.

RecordsAffected

Gets the number of rows changed, inserted, or deleted by execution of the Transact-SQL statement.

VisibleFieldCount

Gets the number of fields in the SqlDataReader that are not hidden.

 

LabView doesn't:

dgholstein_0-1648659699166.png

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?

 

 

0 Kudos
Message 1 of 4
(951 Views)

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.

0 Kudos
Message 2 of 4
(938 Views)
Solution
Accepted by topic author dgholstein

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.

Message 3 of 4
(918 Views)

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.

0 Kudos
Message 4 of 4
(899 Views)