Problems with "Friend"

Posted on 2011-09-30
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.
A new era in Cloud training has arrived.

A day that will go down in Cloud history.. But are you ready for it? Will you accept this Cloud challenge?

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 500 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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor ( Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

622 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