Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Problems with "Friend"

Posted on 2011-09-30
Medium Priority
Last Modified: 2013-11-26
I'm having problems accessing some column properties in a DataTable.

Specifically I want to know if the column is computed, so I'm trying to access the Column.Computed setting.

It's visible in the local variable inspector, however when accessed in code I get Property is not accessible in this context because it is Friend.

Code snippit below.

Lots of Googling around brings up information on Friends only being visible in the same assembly (which I already knew), so I'm assuming that the System.Data library is being treated as a different assembly.

Anyone any hints on how to overcome this, or have microsoft given us visibility of parameters that we can't actually use?

Using oDS As New DataSet
            Using oCommand As New SqlCommand("SELECT * FROM tblTasks WHERE TaskID=" & nTaskID, oSQLConn)
                Using oAdapter As New SqlDataAdapter
                    oAdapter.SelectCommand = oCommand
                End Using
            End Using


        End Using

Open in new window

Question by:StuckInTheMud
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
LVL 15

Expert Comment

ID: 36892370
You can use     Column.Expression isnot nothing

 Note that Expression property is public.
Friend ReadOnly Property Computed As Boolean
        Return (Not Me.expression Is Nothing)
    End Get
End Property

Open in new window

LVL 83

Expert Comment

ID: 36892377
How can a "Select * From TableName" return a computed column? Or is that dummy code? Did you try without the using construct?
LVL 15

Expert Comment

ID: 36892440
A Computed column is a client side column.
It hasn´t any storage.
NetFramework include code to evaluate the Expression each time you query the value based on other fields on same record.

Note that you can add or remove computed columns to any table also when datatable is filled.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 40
ID: 36892470
A Friend property is accessible only inside of the project in which it was defined. So only the dll that defines the DataColumn object can get its value.

Look at the documentation for the DataColumn Members, and you will see that Computed is not listed as a property.

In order to help you in debugging, the debugger shows you more than what you can access in your code. If they declared it as Friend, they probably had a good reason, and it was probably the following:

A query can return the result of a calculation in the SQL, but it is not a computed column, it is a value as any other. As hinted to by CodeCruiser, a command will never return a computed column. A computed column is created in your code and added to the DataTable created by Fill. Since you do it yourself, you know it is computed and do not need the property. But the class needs it internally in order to work.

Author Comment

ID: 36892482
The computed columns are server-side, defined in the table.

Therefore * can return a computed column, because the client does not know that it is computed, as the server has prepared it during the query execution. The information about this is in the schema.

.Expression is retuning empty for all columns.

LVL 40
ID: 36892834
The computed column is your way of seeing things.

But as far as the DataTable is concerned, it is a value just as any other. It does not see the column as being computed. It received a String, a Date, an Integer and does not care if it was computed. Since the computation is not done in the table itself, it is not seen as computed.

Author Comment

ID: 36892913
It's not the data I'm interested in (and, as I've said, I do understand how it's seen by the client), it's the schema behind, which is populated into the DataTable schema.

The VS inspector can see the information I'm after, it's just that I cannot access it programatically.

Anyway, give the information provided on Friend parameters (which ended up confirming what I had thought was the case), I'm now obtaining the information I require directly from the server sys tables as it is a lot less hassle.

LVL 15

Accepted Solution

x77 earned 2000 total points
ID: 36893209
Programmers using  Private  for fields, methods or properties that is not convenient to expose.
There are internal to program design.

Friend is same as Private for external organizations. You must consider this method don´t exist as on next version it can change name or behaviour.

By sample, if you get a PrintPreview control on Net 1.1, you can think that you can access to Toolbar (Friend) using control name by sample, but your code don´t works on Net 2 as this control is changed.

You can use reflection to access to private and Friend members, but Microsoft don´t grants any compatibility for next version for private or friend members.
LVL 15

Expert Comment

ID: 36893246
About  Query computed columns.

You can see the Column ReadOnly property.
Others columns, same Oracle RowId are also ReadOnly and don´t afect the autogenerated Insert,Update clauses.

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question