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
  • 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.
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.
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails


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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now