Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Problems with "Friend"

Posted on 2011-09-30
9
Medium Priority
?
448 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net 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 …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Screencast - Getting to Know the Pipeline
Suggested Courses

886 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