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
Solved

Problems with "Friend"

Posted on 2011-09-30
9
434 Views
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?




Jim
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
                    oAdapter.Fill(oDS)
                End Using
            End Using

            Console.Write(oDS.Tables(0).Columns(0).Computed)

        End Using

Open in new window

0
Comment
Question by:StuckInTheMud
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 15

Expert Comment

by:x77
ID: 36892370
You can use     Column.Expression isnot nothing

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

Open in new window

0
 
LVL 83

Expert Comment

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

Expert Comment

by:x77
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.
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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.
0
 

Author Comment

by:StuckInTheMud
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.



Jim
0
 
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.
0
 

Author Comment

by:StuckInTheMud
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.



Jim
0
 
LVL 15

Accepted Solution

by:
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.
0
 
LVL 15

Expert Comment

by:x77
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.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 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